When we put a key instance say “key” and a Value instance say “value” in a HashMap class using put() method , what does the HashMap class do internally . How does it retrieve the value back when we say hashMap.get(key) ?
Edit: I do not want details here , basically trying to understand the bigger picture and the role of equals() and hashcode() method in put() and get() operations.
If you talk about higher picture it is just like below.Here i refer item as a
keyofMapWhile Putting items.
hashcodeof keybasketwith thathashcodeis present then use theequalsmethod on the key search the keys i that basket to determine if the element is to be added or replace.Get:
hashcodeof keyequalson the key will return you that element from that basket.