R

Ram Sharma • 3.40K Points
Extraordinary

Q. What happens when a duplicate key is inserted in a HashMap?

  • (A) It throws an exception
  • (B) It ignores the new key
  • (C) The old value is replaced
  • (D) Both values are stored
  • Correct Answer - Option(C)
  • Views: 8
  • Filed under category Java
  • Hashtags:

Explanation by: Ram Sharma
`HashMap` allows only one value per key, and inserting a duplicate key replaces the old value.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.