Courseiva
Controlling Program FlowhardMultiple SelectObjective-mapped

1Z0-829 Controlling Program Flow Practice Question

Which two statements about the enhanced for-each loop in Java are true? (Choose two.)

⚠ Common exam trap

Candidates often think the enhanced for-each loop can safely modify collections because it 'hides' the iterator, but it actually exposes the same fail-fast behavior as explicit iterator usage.

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

It requires the target to implement the Iterable interface, except for arrays.

The enhanced for-each loop requires the target to implement the Iterable interface, except for arrays, which are handled natively by the compiler using index-based iteration. This is specified in the Java Language Specification (JLS §14.14.2), where arrays are a special case that does not require Iterable.

Answer analysis

Option-by-option breakdown

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

  • It requires the target to implement the Iterable interface, except for arrays.

    Why this is correct

    For arrays, the loop works directly; for other objects, they must implement Iterable.

  • It can safely modify the underlying collection during iteration.

    Why it's wrong here

    Modifying a collection during for-each iteration usually throws ConcurrentModificationException.

  • It can be used to iterate directly over a Stream object.

    Why it's wrong here

    Stream does not implement Iterable; you need to use Stream's forEach method or collect into a collection.

  • It can be used to iterate over an array.

    Why this is correct

    The for-each loop works with arrays and collections.

  • It provides an implicit counter variable that can be accessed.

    Why it's wrong here

    No counter is available; you must use a traditional for loop to track indices.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.