Hashmap works on principle of Hashing. Hashing principle based on
1. Hash function, which hashCode() in Object class.
2. Hash value, return value of hashCode().
3. Bucket, contains Key-Value pair.
hashCode() function which returns an integer value is the Hash function. The important point to note that , this method is present in Object class
This is the code for the hash function(also known as hashCode method) in Object Class :
public native int hashCode();
The most important point to note from the above line : hashCode method return int value.So the Hash value is the int value returned by the hash function.
Bucket contains key-value pairs ie., Map.Entry<key,value>.
Map will have multiple Entry <key,value> elements follows Set data structure.
When ever item is getting inserted, Hash Value for the key will be generated.
Each value is associated with Hash Value. Association between Hash Value & Entry follows Linked List data structure but not java.util.LinkedList.
When entry for key Sachin is trying to insert,
Hash Value will be generated here 002, and it is linked to Entry(Sachin,Cricket).
When second element with Key Sandeep is trying to insert , hash value for Sandeep will be generated ie., here 004 and associated entry is linked to hashvalue 004.
When another element with Key Sehwag is trying to insert , assume hash value for Sehwag will be generated ie., here 004 since there is another entry linked to same hash value entry will be linked to end item of hash values linked list. Here , Sehwag entry linked to 004 hash values linked list end item that is Sandeep entry