for (Integer x : list) {
if (x == 0) list.remove(x);
}What problem occurs?
- A
for-each cannot iterate ArrayList
- B
list.remove takes an int index, not an Integer
- C
Nothing happens
- Dcheck_circle
ConcurrentModificationException because the list is modified during a for-each
Explanation
Modifying a collection while iterating with an enhanced for-loop triggers ConcurrentModificationException. Use an explicit Iterator or an index-based loop.