1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 74


Given:

What is the result?

Show Answer
Correct Answer: C

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.

Discussion

5 comments
Sign in to comment
StavokOption: C
Jun 7, 2023

C is correct java.util.ConcurrentModificationException

tmuralimanoharOption: C
Jun 29, 2023

Answer: C

OmnisumemOption: C
Sep 8, 2023

Tested: C.

mendjijetOption: C
Feb 8, 2024

C is ok java.util.ConcurrentModificationException

ASPushkinOption: C
Jul 17, 2024

answer: C should be it.remove(); interesting that it wil be ok : if (it.next() == 2) { al.remove(2; break;