1Z0-829 Working with Arrays and Collections Practice Question
Which of the following creates an immutable map with two entries?
⚠ Common exam trap
Watch out — candidates often confuse creating a mutable copy of an immutable map (option A) with the immutable map itself, or they overlook that `Map.of()` directly produces an immutable map without needing a wrapper.
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
✓
Map.of("a",1,"b",2)
`Map.of()` returns an immutable map containing exactly the key-value pairs provided as arguments. This factory method was introduced in Java 9 and creates a fixed-size, unmodifiable map with the two entries "a"→1 and "b"→2.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
new HashMap<>(Map.of("a",1,"b",2))
Why it's wrong here
Incorrect: this creates a mutable copy of the immutable map.
- ✓
Map.of("a",1,"b",2)
Why this is correct
Correct: returns an immutable map with two entries.
- ✗
Collections.emptyMap()
Why it's wrong here
Incorrect: this returns an empty immutable map.
- ✗
None of the above
Why it's wrong here
Incorrect: Map.of works.
- ✗
new HashMap<>()
Why it's wrong here
Incorrect: this creates an empty mutable map.
Go deeper
Related to this question
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 →
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.