Maybe it would help to think of the implementation of a Map.
For the most part a map is an array. So lets say we have a Map of size 20, it is basically an Object (Object array of size 20).
When you put something into a Map it performs a math function on the key you pass in, in the case of HashMap on the hashcode of the key.
example: if you do map.put("key", value);
the map will call hascode on key. This usually returns something on the order of 12345685 (fairly large number). that has to be mapped to fit into the size of the map (20 in this case).
you would do something like
(12345685 * 31) % 20
In this case it would be 15 so the object referenced by value (in the put) would be placed at index 15.
It is possible to have two hashcodes map to the same index in the map. If this happens they are compaired using the equals() method if they are not equals() they are attached in some way, often a linked list, to index 15.
I hope that helps.
posted 15 years ago
It means Map will be like this :
If I want to find out value LPO , then first a algorithm is applied to this value & this gives us key ( probably hashCode() method ) then first JVM will see the rows which has key 6 . they are two so now it will apply equals() method & finally our element will come out .
Is everything is right !!!
thanks . [ January 27, 2005: Message edited by: rathi ji ]