Courseiva
Question 114 of 513
Working with Arrays and CollectionseasyMultiple SelectObjective-mapped

1Z0-829 Working with Arrays and Collections Practice Question

Which THREE are valid ways to iterate over a Map<String, Integer>?

⚠ Common exam trap

Watch out — candidates often think `Map` itself is iterable (like `Collection`), but it is not; you must use `keySet()`, `values()`, or `entrySet()` to obtain an iterable view, and `forEach` is a default method on `Map` that works directly.

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

for (String key : map.keySet()) { }

`Map.keySet()` returns a `Set<String>` containing all keys, which can be iterated using an enhanced for-each loop. This is a standard way to access keys in a `Map<String, Integer>`.

Answer analysis

Option-by-option breakdown

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

  • for (Map.Entry<String, Integer> entry : map) { }

    Why it's wrong here

    Map does not implement Iterable.

  • for (String key : map.keySet()) { }

    Why this is correct

    Valid.

  • map.forEach((k, v) -> { });

    Why this is correct

    Valid.

  • for (Integer value : map.values()) { }

    Why it's wrong here

    Iterates values, not entries.

  • for (Map.Entry<String, Integer> entry : map.entrySet()) { }

    Why this is correct

    Valid.

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 11, 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.