我使用迭代器从链接的哈希映射中删除项目但获取并发修改异常
Iterator<Integer> it = linkedMap.keySet().iterator();
while (it.hasNext()) {
java.lang.Integer key = it.next();
if (key.equals(number)) {
linkedMap.remove(key);
}
}
请帮助..
答案 0 :(得分:1)
检查条件不是iterator
linkedMAp
Iterator<Integer> it = linkedMap.keySet().iterator();
while (it.hasNext()) {
Integer key = it.next();
if (key.equals(number)) {
// Remove the current element from the iterator and the list.
it.remove();
}
}
检查这个问题就像你的一样
Iterating through a Collection, avoiding ConcurrentModificationException when removing in loop