LearnFrenzy
Sign in Take a free test

HashMap and TreeMap · HashMap and TreeMap MCQ · Question 16

Changing a key after inserting it Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 16 Back to Exercise

A mutable object is used as a HashMap key and a field used in its hashCode is changed afterwards. What happens?

  • A The map updates automatically
  • B The entry usually cannot be found any more, because it sits in the bucket for the old hash Correct
  • C An exception is thrown
  • D The key is removed
Correct Answer: Option B

Prefer immutable keys.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links