how hashmap works in java

Most os you will agree that HashMap is most favorite topic discussion in interviews now-a-days.I have gone throught several discussions whith my colleaguses time to time and it realy helped.Now,I am continuing this discussion whith you all.

Single statment answer
if anybody asks me to describe “How HashMap works?” I simplly answer: “On principle of Hashing”. As simple as it is.Now before answering it ,one must be very sure to know at leastbasics of Hashing.Ringht??

What is Hashing
Hashing is simple form,is a way to assiging a unique code for any variable/object after applying any formula/alorithm on its propertis.A true Hashing function must fllow this rule:

Hash function shoud return the sam hash code each and every time,when function is applied on same hash code consistenly.

All objects in java inherit a defualt implmentation of hahCode() function defind in Object class. This function produce hahs code by typically converting the internal address od the object into an integer,thus producing diffrent hah codes for all diffrent objects.

A litte about Entry class

A map by definition is :”An object that maps keys to values“. Very easy ..right?

1
2
3
4
5
6
7
static class Entry<K,V> implemnts Map.Entry<K,V>{
final K key;
V value;
Entry<K,V> next;
final int hash;
}

Surely Entry class has key and value mapping