Hashmap stores a key-value pair in Map.Entry static nested class implementation. HashMap works on hashing algorithm and uses hashcode() and equals() method in put() and get() methods.
When we call put() method by passing key-value pair, HashMap uses key hashcode() with a hashing to find out the index to store the key-value pair. The entry will be stored in the LinkedList, so if there is an already existing entry, it uses equals() method to check if the passed key is already exists, if yes its override the value else it creates a new entry and stores the key-value pair.
When we call get() method by passing key, again it uses the hascode() to find the index in the array and then use equals() method to find the correct entry and return its value.

The other things to know about HashMap is capacity, load factor and threshold resizing. HashMap initial default capacity is 16 and load factor is 0.75.

Leave a comment