I can ensure these points
only if you have properly implemented the
hashCode-Contract and
evaluated the hashCode using the fields used to determine the equality:
1. When you try to put <key,object> pair in a hashmap, a hashCode is generated corresponding to the key.
2. If that hashCode has not been already generated for some previous key of any <key,object> pair, a new <Key,object> pair is added to the hashmap.
3. If the hashCode code has been already generated, then hashCode() method internally calls the equals() method to check whether this new object is identical with the old object that is already in the map(with same key).
--> If equals() returns true: then the new object overwrites the previous object in the hashmap.(i.e. no change in hashMap size)
--> If equals() returns false: then a new object will be added to hashmap with the same key(i.e. size of hashmap will increase by one)
I think this is how <key,object> pairs are put into a hashMap..,
But things are not very much clear to me what happens actually when we retrieve a particular object from a bucket with multiple objects(i.e.objects with same key). If somebody knows please let me know...