How many objects will be there inside the hashmap?

1 Answers
Answered by suresh

Java HashMap Objects Count - Interview Question

How many objects will be there inside the HashMap in Java?

In a Java HashMap, the number of objects inside the map will depend on the number of key-value pairs that have been inserted into the map. Each key-value pair counts as one object in the HashMap.

If there are n key-value pairs inserted into the HashMap, then the total number of objects inside the HashMap will be n.

It is important to note that the HashMap does not allow duplicate keys, so each key in the map must be unique. However, the values associated with the keys can be duplicates.

Answer for Question: How many objects will be there inside the hashmap?