aps*_*aps 22 java collections concurrentmodification
如果我在使用for-each循环迭代它时修改Collection,它会给出ConcurrentModificationException.有没有解决方法?
jzd*_*jzd 11
一个解决方法是保存更改并在循环后添加/删除它们.
例如:
List<Item> toRemove = new LinkedList<Item>();
for(Item it:items){
if(remove){
toRemove.add(it);
}
}
items.removeAll(toRemove);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
50218 次 |
| 最近记录: |