Courseiva
Question 180 of 513
Working with Arrays and CollectionseasyMultiple ChoiceObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

Examine the code: List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); for (String s : list) { list.remove(s); } What is the outcome?

⚠ Common exam trap

Watch out — candidates often assume the for-each loop will safely remove elements one by one, not realizing that the implicit iterator throws an exception on structural modification.

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

A ConcurrentModificationException is thrown

The for-each loop internally uses an Iterator to traverse the list. When the list is structurally modified (via `list.remove()`) during iteration without using the iterator's own `remove()` method, the iterator detects a concurrent modification and throws a `ConcurrentModificationException`. This is a fail-fast behavior of the `ArrayList` iterator.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • A ConcurrentModificationException is thrown

    Why this is correct

    Modifying list during iteration with for-each throws exception.

  • The loop completes successfully and list becomes empty

    Why it's wrong here

    Exception prevents completion.

  • An IllegalStateException is thrown

    Why it's wrong here

    ConcurrentModificationException is thrown.

  • The loop completes successfully and list contains [B]

    Why it's wrong here

    Exception thrown.

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 →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 25, 2026

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.

Loading comments…

Sign in to join the discussion.

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.