LearnFrenzy
Sign in Take a free test

HashMap and TreeMap · HashMap and TreeMap MCQ · Question 1

Putting the same key twice Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

What happens when you put a key that already exists in a HashMap?

  • A A duplicate entry is added
  • B The old value is replaced, and put returns the old value Correct
  • C An exception is thrown
  • D The new value is ignored
Correct Answer: Option B

Keys are unique.

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