如何交换列表<;列表<;字符串>&燃气轮机;java中使用索引的数组值?
我有如何交换列表<;列表<;字符串>&燃气轮机;java中使用索引的数组值?,java,list,arraylist,key,data-interchange,Java,List,Arraylist,Key,Data Interchange,我有列表这样的数据 List<List<String>> repdata = [ ["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"], ["1186","R","5t","R","01","L","TP","00110","1854","2016","FE LL","06W3","01","19065","FB01"],
列表
这样的数据
List<List<String>> repdata = [
["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"],
["1186","R","5t","R","01","L","TP","00110","1854","2016","FE LL","06W3","01","19065","FB01"],
["1187","R","6t","H","06","L","TP","04333","1864","2015","CF FE SL","0209","FD22","19845",null],
["1188","R","7t","H","06","L","PR","04041","6951","2015","CC CT FE GN PC","0070","00","36590","LB00"],
["1189","R","8t","H","06","L","WS","04290","4450","2014","CF EN FE PC TP","0070","EA30","28320.00",null],
["1190","R","9t","H","06","L","LA","04915","4430","2015","CF DK FE RR TC","0040","10","23680","FB10"],
["1191","R","10t","H","06","L","LF","04335","2532","2015","CF FE GE","0040","FC10","22970",null],
["1192","R","11t","H","06","L","SA","04772","8345","2015","BZ C8 FE","01D6","13","33390","LC13"]]
List<List<String>> repdata = [
["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","FF20","23840","FF20"],//interchange 12th with 14th as 14th !=null
["1186","R","5t","R","01","L","TP","00110","1854","2016","FE LL","06W3","FB01","19065","FB01"],//interchange 12th with 14th as 14th !=null
["1187","R","6t","H","06","L","TP","04333","1864","2015","CF FE SL","0209","FD22","19845",null],//leave 12th as IT IS as 14th ==null
["1188","R","7t","H","06","L","PR","04041","6951","2015","CC CT FE GN PC","0070","00","36590","LB00"],//interchange 12th with 14th as 14th !=null
["1189","R","8t","H","06","L","WS","04290","4450","2014","CF EN FE PC TP","0070","EA30","28320.00",null],//leave 12th as IT IS as 14th ==null
["1190","R","9t","H","06","L","LA","04915","4430","2015","CF DK FE RR TC","0040","10","23680","FB10"],//interchange 12th with 14th as 14th !=null
["1191","R","10t","H","06","L","LF","04335","2532","2015","CF FE GE","0040","FC10","22970",null],//leave 12th as IT IS as 14th ==null
["1192","R","11t","H","06","L","SA","04772","8345","2015","BZ C8 FE","01D6","13","33390","LC13"]]//interchange 12th with 14th as 14th !=null
我想用这个逻辑比较并交换'20'和'FF20'
If 14th index value != null then assign,
12th index=14th index value.
else if 14th index value ==null,
then leave 12th index=12th index value as it is.
对于List
repdata中的所有内部列表,必须重复此操作
所以,我的最终列表>是这样的
List<List<String>> repdata = [
["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"],
["1186","R","5t","R","01","L","TP","00110","1854","2016","FE LL","06W3","01","19065","FB01"],
["1187","R","6t","H","06","L","TP","04333","1864","2015","CF FE SL","0209","FD22","19845",null],
["1188","R","7t","H","06","L","PR","04041","6951","2015","CC CT FE GN PC","0070","00","36590","LB00"],
["1189","R","8t","H","06","L","WS","04290","4450","2014","CF EN FE PC TP","0070","EA30","28320.00",null],
["1190","R","9t","H","06","L","LA","04915","4430","2015","CF DK FE RR TC","0040","10","23680","FB10"],
["1191","R","10t","H","06","L","LF","04335","2532","2015","CF FE GE","0040","FC10","22970",null],
["1192","R","11t","H","06","L","SA","04772","8345","2015","BZ C8 FE","01D6","13","33390","LC13"]]
List<List<String>> repdata = [
["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","FF20","23840","FF20"],//interchange 12th with 14th as 14th !=null
["1186","R","5t","R","01","L","TP","00110","1854","2016","FE LL","06W3","FB01","19065","FB01"],//interchange 12th with 14th as 14th !=null
["1187","R","6t","H","06","L","TP","04333","1864","2015","CF FE SL","0209","FD22","19845",null],//leave 12th as IT IS as 14th ==null
["1188","R","7t","H","06","L","PR","04041","6951","2015","CC CT FE GN PC","0070","00","36590","LB00"],//interchange 12th with 14th as 14th !=null
["1189","R","8t","H","06","L","WS","04290","4450","2014","CF EN FE PC TP","0070","EA30","28320.00",null],//leave 12th as IT IS as 14th ==null
["1190","R","9t","H","06","L","LA","04915","4430","2015","CF DK FE RR TC","0040","10","23680","FB10"],//interchange 12th with 14th as 14th !=null
["1191","R","10t","H","06","L","LF","04335","2532","2015","CF FE GE","0040","FC10","22970",null],//leave 12th as IT IS as 14th ==null
["1192","R","11t","H","06","L","SA","04772","8345","2015","BZ C8 FE","01D6","13","33390","LC13"]]//interchange 12th with 14th as 14th !=null
List repdata=[
[“1185”、“R”、“4t”、“G”、“06”、“L”、“GT”、“04309”、“2546”、“2015”、“CF FE”、“01H1”、“FF20”、“23840”、“FF20”],//将第12位与第14位交换为第14位!=null
[“1186”、“R”、“5t”、“R”、“01”、“L”、“TP”、“00110”、“1854”、“2016”、“FE LL”、“06W3”、“FB01”、“19065”、“FB01”],//将第12位与第14位交换为第14位!=null
[“1187”,“R”,“6t”,“H”,“06”,“L”,“TP”,“04333”,“1864”,“2015”,“CF FE SL”,“0209”,“FD22”,“19845”,null],//将第12个保留为第14个==null
[“1188”、“R”、“7t”、“H”、“06”、“L”、“PR”、“04041”、“6951”、“2015”、“CC CT FE GN PC”、“0070”、“00”、“36590”、“LB00”],//将第12位与第14位交换为第14位!=null
[“1189”,“R”,“8t”,“H”,“06”,“L”,“WS”,“04290”,“4450”,“2014”,“CF EN FE PC TP”,“0070”,“EA30”,“28320.00”,空],//保留第12个,因为它是第14个==空值
[“1190”、“R”、“9t”、“H”、“06”、“L”、“LA”、“04915”、“4430”、“2015”、“CF DK FE RR TC”、“0040”、“10”、“23680”、“FB10”],//将第12位与第14位交换为第14位!=null
[“1191”,“R”,“10t”,“H”,“06”,“L”,“LF”,“04335”,“2532”,“2015”,“CF FE GE”,“0040”,“FC10”,“22970”,null],//保留第12个,因为它是第14个==null
[“1192”,“R”,“11t”,“H”,“06”,“L”,“SA”,“04772”,“8345”,“2015”,“BZ C8 FE”,“01D6”,“13”,“33390”,“LC13”]//将第12和第14交换为第14=无效的
我尝试删除第12个索引,然后在第12个索引处添加第14个索引值
但是我不断地得到concurrentmodificationexception
有人能帮我解决这个问题吗?为了用第14个元素替换列表中的第12个元素,您必须编写如下代码:
List<List<String>> listOfLists = ...;
for( List<String> list: listOfLists ){
String el;
if( list.size() > 14 && // list is long enough
(el = list.get(14)) != null ){ // element is not null
list.set( 12, el ); // replace element at index 12
}
}
列表列表=。。。;
对于(列表:ListofList){
字符串el;
如果(list.size()>14&&//list足够长
(el=list.get(14))!=null){//元素不为null
set(12,el);//替换索引12处的元素
}
}
请显示引发异常的行的相关代码。列表
(s)不是数组。您使用get
和set
。您是如何运行此功能的?你不能创建这样的列表。您是否正在使用像Eclipse这样的现代IDE?它会向你们指出这一点。@Bohemian请不要在我的code.oops中添加bug。很抱歉。