Given:
What is the result?
Given:
What is the result?
The code will throw a ConcurrentModificationException at runtime. The reason is that the modification of the ArrayList (using al.remove(2)) occurs while it's being iterated. The Iterator's contract specifies that modifying the collection while iterating through it, using methods other than those provided by the iterator itself, results in a ConcurrentModificationException.
answer: C should be it.remove(); interesting that it wil be ok : if (it.next() == 2) { al.remove(2; break;
C is ok java.util.ConcurrentModificationException
Tested: C.
Answer: C
C is correct java.util.ConcurrentModificationException