Question 306 of 513
1Z0-829 Controlling Program Flow Practice Question
A developer wrote a method that uses a for-each loop to iterate over a list of strings and remove elements that match a certain condition. However, the method throws a ConcurrentModificationException at runtime. What is the most likely cause?
⚠ Common exam trap
Test-takers frequently confuse the ConcurrentModificationException with other exceptions (like UnsupportedOperationException) or mistakenly think the for-each loop itself is the problem, rather than recognizing that direct list modification during iteration is the root cause.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The loop modifies the list by calling remove() on the list itself.
A for-each loop internally uses an Iterator to traverse the list. If the list is structurally modified (e.g., by calling remove() directly on the list) during iteration, the iterator's expected modCount will differ from the actual modCount, triggering a ConcurrentModificationException. This is a fail-fast behavior of the ArrayList and other Collection implementations.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The loop uses a for-each loop with an array instead of a list.
Why it's wrong here
Arrays do not produce ConcurrentModificationException.
- ✗
The loop uses an iterator that is not properly initialized.
Why it's wrong here
The for-each loop manages its own iterator internally.
- ✗
The list is unmodifiable.
Why it's wrong here
An unmodifiable list would throw UnsupportedOperationException, not ConcurrentModificationException.
- ✓
The loop modifies the list by calling remove() on the list itself.
Why this is correct
Modifying the list directly while iterating with a for-each loop causes ConcurrentModificationException because the iterator is not updated.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 25, 2026
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.