我是Java新手,我想获得两个arraylist值相同的索引,但是两个arraylist的大小/长度不同。这是工作代码:
List<String> new_valueString = new ArrayList<>();
List<String> new_fieldsString = new ArrayList<>();
List<String> oldValueString = new ArrayList<>();
List<String> oldFieldsString = new ArrayList<>();
if (new_fieldsString.size() != 0 && new_valueString.size() != 0) {
for (int l = 0; l < new_fieldsString.size(); l++) {
if (new_fieldsString.get(l).equalsIgnoreCase(oldFieldsString.get(l))) {
field_index = l;
if (!new_valueString.get(field_index).contains(oldValueString.get(field_index))) {
ifUpdated = true;
} else {
ifUpdated = false;
}
}
}
}
我想获取new_fieldsString和oldFieldsString之间相同值的索引,并使用该索引来比较new_valueString和oldValueString。
答案 0 :(得分:1)
您好,您需要两个句子,一个用于第一个数组,第二个与短数组列表进行比较,当您发现条件为真时,别忘了打破循环,像这样:
List<String> new_valueString = new ArrayList<>();
List<String> new_fieldsString = new ArrayList<>();
List<String> oldValueString = new ArrayList<>();
List<String> oldFieldsString = new ArrayList<>();
if (new_fieldsString.size() != 0 && new_valueString.size() != 0) {
for (int l = 0; l < new_fieldsString.size(); l++) {
for (int m = 0; m < oldFieldsString.size(); m++) {
if (new_fieldsString.get(l).equalsIgnoreCase(oldFieldsString.get(m))) {
if (!new_valueString.get(l).contains(oldValueString.get(m))) {
ifUpdated = true;
} else {
ifUpdated = false;
}
break;
}
}
}
}