【发布时间】:2016-09-06 08:38:46
【问题描述】:
删除(整数列表)列表中的一个元素时出错。 我使用迭代器删除该元素
这是我的代码:
List<List<Integer>> list = new ArrayList<List<Integer>>();
....
....
Iterator<List<Integer>> myListIterator = list.iterator();
int ct1 = 0;
while (myListIterator.hasNext()) {
List<Integer> val = myListIterator.next(); // here is the error
if(ct1 == val.get(0))
list.remove(val);
ct1++;
}
我收到了这个错误信息:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.util.ArrayList$Itr.next(Unknown Source)
有人知道我的代码有什么问题吗? 谢谢各位!
【问题讨论】: