0% found this document useful (0 votes)
3 views2 pages

Understanding HashMap Functionality

A HashMap creates 16 linked lists in the heap by default and doubles its capacity when the load factor reaches 75%. It stores key-value pairs where keys must be objects, and uses their hashCode to determine the bucket index for storage. In case of hash collisions, the JVM checks for key equality to either overwrite the existing value or add a new node to the linked list in the same bucket if the keys are different.

Uploaded by

vanshikrplani01
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Understanding HashMap Functionality

A HashMap creates 16 linked lists in the heap by default and doubles its capacity when the load factor reaches 75%. It stores key-value pairs where keys must be objects, and uses their hashCode to determine the bucket index for storage. In case of hash collisions, the JVM checks for key equality to either overwrite the existing value or add a new node to the linked list in the same bucket if the keys are different.

Uploaded by

vanshikrplani01
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

HashMap working

1)​ Creates 16 linked lists in heap by default.


2)​ Load Factor:If a hashmap reaches 75% of its capacity the size of the hashmap doubles
the existing capacity this is done by load factor

3)​ Stores key value pairs where the key must be an object instead of primitive types. Then
JVM will get the hashcode of the key it will use the .hashCode() from the object class.
4)​ Using that hashCode the JVM finds the bucket index where the key value pair needs to
be stored
5)​ Hash Collision: When 2 keys generate the same hashCode and hence same bucket
index which makes JVM tries to add a key value pair to a bucket already having some
data is called hash Collision.

6)​ If hash collision happens 1st JVM will check if the keys are equal(only keys will be
checked) if they are equal that node will be overwritten to the new jay value since the
keys are the same hence not allowing duplicate keys. If the keys are unequal a new
node will be added to the linked list in the same bucket.

You might also like