Internals of how the HashMap put() and get() methods work (basic logic only )
If you talk about higher picture it is just like below.Here i refer item as a key
of Map
While Putting items.
- Calculate
hashcode
of key - If
basket
with thathashcode
is present then use theequals
method on the key search the keys i that basket to determine if the element is to be added or replace. - If not there then create new basket (rehashing) and add that element to that.
Get:
- Get the
hashcode
of key - Go to that basket
- Iterate using
equals
on the key will return you that element from that basket.