Question 364 of 513
1Z0-829 Working with Arrays and Collections Practice Question
A HashMap uses a mutable object as a key. After adding the key-value pair, the key's fields are changed such that its hashCode changes. Which statement is true?
⚠ Common exam trap
A common mix-up: candidates assume HashMap automatically handles key mutations or that Java enforces key immutability, but in reality, the contract requires keys to be immutable for correct behavior, and no runtime check is performed.
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 value may not be retrievable using the modified key
When a HashMap uses a mutable object as a key and the key's hashCode changes after insertion, the key is stored in the bucket corresponding to its original hash code. The modified key's new hash code will likely map to a different bucket during retrieval, so the value may not be found. Option B is correct because the value may not be retrievable using the modified key, depending on whether the new hash code leads to the same bucket and whether equals() still matches.
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 value can still be retrieved using the modified key
Why it's wrong here
Hash code mismatch may prevent retrieval.
- ✓
The value may not be retrievable using the modified key
Why this is correct
Changed hash leads to lookup in wrong bucket.
- ✗
The entry is automatically moved to the correct bucket
Why it's wrong here
HashMap does not monitor key mutations.
- ✗
An IllegalArgumentException is thrown when modifying the key
Why it's wrong here
No exception from key mutation.
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.