Skip to content
Sharp

Core Java · interview question

Consider a HashMap storing product names as keys and their prices as values. What potential issue should you consider when using mutable objects as keys?

Multiple choiceHardchapter-4-curatedpremiumcore-javacode-reading-with-collections
Choose one answer
Answer and explanation

Correct answer

D. Keys might not be found if they are mutated after insertion.

Why

If a key's state changes after being added to the HashMap, its hash code might change, leading to retrieval failure since the object cannot be located in the bucket where it was originally placed.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →