Register now or log in to join your professional community.
here the concept wil go bit more narrow, this is dependent over the implementation of HashMap,
The Key Object must follow the contract of HashCode and Equals method.
For Specific Bucket of HashMap we get by HashCode and if the value Exist aleady than there should be the use of equals method to find the value in the bucket.
So further down to bucket the collision will be handled on the base of object equality.
As the bucket is implemented using LinkedList than the Equal KeyObject will be Updated otherwise new object can be added to the bucket.
If the map previously contained a mapping for this key, the old value is replaced by the specified value.
Explanatation:
public V put(K key, V value)
Associates the specified value with the specified key in the map . If the map previously contained a mapping for this key, the old value is replaced by the specified value.
The map simply drops its reference to the OLD VALUE. If nothing else holds a reference to the object(OLD), that object becomes eligible for GARBAGE COLLECTION.