[Percy]: When I use an object as a key value, is a reference to the object stored in the Map
or is an entire new object created and a reference to this new object store in the Map?
Consider the foll.
1. d is a ref. to a Dog object having one String member variable.
2. I use the above reference as a key in a Map.
3. I now change the value of the above mentioned String variable in such a way that the hashcode also changes (assume that the length of the string variable is the hashcode).
4. Does the position of the object in the Map change as the hashcode has changed? Is the value corresp. to the key now placed in a different 'bucket'?
Whenever you change the value of a key after you've already inserted the key into a HashMap (or any Map, probably) you may get unpredictable results which can be summarized as "it doesn't work". The key is still in the map at the old location, but you probably won't be able to find it any more. Basically, you never want to change the value of a key after putting it in a Map. [ May 07, 2007: Message edited by: Jim Yingst ]