1.

What happens if we put a key object in a HashMap which exists?(a) The new object replaces the older object(b) The new object is discarded(c) The old object is removed from the map(d) It throws an exception as the key already exists in the mapThe question was asked during a job interview.This intriguing question originated from Data Structures-HashMap in section java.util – The Collections Framework of Java

Answer»

Correct answer is (a) The new object replaces the older object

To explain I would SAY: HASHMAP always CONTAINS unique keys. If same KEY is inserted again, the new object replaces the PREVIOUS object.



Discussion

No Comment Found

Related InterviewSolutions