我需要比较两个不同大小的Arraylists。比较两个阵列列表和迭代器
我可以用两个循环做到这一点 - 但我需要使用迭代器。
第二个循环只迭代一次而不是n次。
while (it.hasNext()) {
String ID = (String) Order.get(i).ID();
j = 0;
while (o.hasNext()) {
String Order = (String) Order.get(j).ID();
if (myOrder.equals(Order)) {
//do sth
}
j++;
o.next();
}
i++;
it.next();
}
您似乎误解了如何使用迭代器。如果你使用迭代器,你不需要调用'String ID = list.get(i).ID();',你只需调用:'String ID = it.next()。ID();'。 – assylias
*我需要比较*的一些更多细节将会有所帮助。你想检查它们是否包含相同的对象*或者它们是否在相同的位置包含相同的对象*。 –
如果您正在使用现代编程IDE(如eclipse),请开始使用自动格式化。在阅读此代码后,我将不得不再次与我的医生签署一份协议:P – brimborium