, , , list.remove() list.remove() ConcurrentModificationException, iterator.remove() - ?
:
List<String> list = new ArrayList<>(Arrays.asList("a", "b", "c", "d"));
for (Iterator<String> iter = list.iterator(); iter.hasNext(); ) {
if (iter.next().equals("b")) {
}
}
# 1, . # 2 ( # 1), iter.next() iter.next() ConcurrentModificationException.
, - , . , , , , , , .. ConcurrentModificationException .
, , , .
iterator.remove() , . , , , , . :
Iterator<String> i1 = list.iterator();
Iterator<String> i2 = list.iterator();
i1.remove();
i2.remove();
, . , , i2.remove() i2.remove() ConcurrentModificationException.