[go: up one dir, main page]

0% found this document useful (0 votes)
6 views1 page

HashMap Internal

The document explains the structure and functioning of a HashMap in Java, detailing how it uses buckets and linked lists to store key-value pairs. It describes the process of adding entries to the map, including how the hash function determines the appropriate bucket index and handles collisions through equality checks. Examples of employee objects and their corresponding values illustrate the insertion process and collision resolution in the HashMap.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

HashMap Internal

The document explains the structure and functioning of a HashMap in Java, detailing how it uses buckets and linked lists to store key-value pairs. It describes the process of adding entries to the map, including how the hash function determines the appropriate bucket index and handles collisions through equality checks. Examples of employee objects and their corresponding values illustrate the insertion process and collision resolution in the HashMap.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

When we create one HashMap like

Map<Employee, String> map=new HashMap<> ();

it will create 16 bucket and bucket start from 0-15

Each bucket internally called one LinkList and every Linklist called Node and each node internally
contains 4 things Key, value, Hash code, next. Suppose I created some employee object

Employee e1=new Employee(1001,"Prakash")

Employee e2=new Employee(1002,"An")

Employee e3=new Employee(1003,"Raku")

Employee e4=new Employee(1004,"Tusar")

when we put some value on map object

map.put(e1,"Dev") then How my HashMap will identify where we need to put this

Then put method internally called

hash(K) function and it will evaluate some hash value

then based on the modular operation it will identify the index

index=hash &(n-1)

suppose it evaluate bucket 6 then will put on bucket 6

again, put some value

map.put(e2,"QA")

again, it will same things

again, evaluate bucket 8. then will put on bucket 8

again, we put some value

map.put(e3,"UAT")

then it evaluates same bucket 6 when hash map check it found already some value is available what
HashMap will do.

(Hashing collusion)

at that time HashMap will check with equal ()

e1. equal(e3)

You might also like