下面是代碼:從一個ArrayList刪除元素,如果它們出現在另一個沒有提高ConcurrentModificationException的
Ledger obj = null;
MyUtilPojo obj1 = null;
Iterator it = toList.iterator();
while (it.hasNext()) {
obj = (Ledger) it.next(); //after first iteration next here produce an error
Iterator it1 = moreToList.iterator();
while (it1.hasNext()) {
obj1 = (MyUtilPojo) it1.next();
if (obj.getId() == obj1.getKey()) {
toList.remove(obj);
}
}
}
這引發錯誤ConcurrentModificationException
,有人可以幫忙嗎?
還看到:http://stackoverflow.com/a/4103007/180100 – 2011-12-21 05:41:18
做'it.remove()' – irreputable 2011-12-21 05:45:33