working with this code i found that when i change the d2 object as abcdef whose hassh code value matches with hello which was declared earlier! but the equal method doesnt matches!!isnt it? even though equal doesnt matches i can able to retrive the value which is assingned for the d2 object key!!
First of all, you got lucky. You are *not* allowed to change the value of a key that is in a map. Doing so can corrupt the map. In this case, it worked because the hashcode didn't change, and you didn't change it to something that would have cause the duplicate rule to the violated.... In most cases, when you change the key, it will corrupt the map, and there is no guarrantee that anything will work as documented.
And why won't equals() return true? The map doesn't clone the keys, it just has a reference to them, so the map is pointing to the same object as what the d2 reference is pointing to.
thus it si contradicting the rule? contract between hashcode and equal();!!! so can any one please help me with this!!!
Which rule are you referring to?
Henry