Monday, March 7, 2016

how the hashmap stores the objects internally?

HashMap stores the values through put(key,value) and gets the values thorugh get(key). The process follows the concept of Hashing.
When we say put(key,value) - Internally hashCode() for the key is calculated and being taken as the input for hashfunction() to find the bucket location for storing.
In case of Collision - while calculating the hashcode() there may be a possibility the key is different but the hashcode() is same, at that time after finding out the bucket location the storing is done in the linked list. Please Note - While storing as the Map.Entry both the key-value is stored.
When Retrieve of the value through key is done then if during the collision where the key's hashcode() may be same then the value is retrived though equals() function to find out the desired key's value.
All credit goes to Anand Builders

No comments:

Post a Comment