下面給出的代碼不會拋出ConcurrentModificationException.But,如果我在LinkedList中添加了2個元素,它會拋出異常。爲什麼?LinkedList上的ConcurrentModificationException
List<String> list = new LinkedList<String>();
list.add("A");
list.add("B");
for (String s : list) {
if (s.equals("B")) {
list.remove(s);
}
}
請訪問http:// stackoverflow.com/a/223929/4290096 –
可能的重複[遍歷列表,避免ConcurrentModificationException在循環中刪除時](http://stackoverflow.com/questions/223918/iterating-through-a-list-avoiding-concurrentmodificationexception - 什麼時候刪除) – nogard
我想問哪個問題更多次,這個或者字符串比較.. – drgPP