Could somebody tell me what the hashcode exactly is? Where to use it? Is it anything related with the key value? if I put: HashMap hm = new HashMap(); hm.put( "one", new Integer( 1 ) ); System.out.println( HM.get( "one" ).hashCode() ); it prints out 1. but if I change Integer object to Float, it prints out 1065353216. what is that?
For more info on the hashCode() method, check it out in the Object class.
It is used a lot internally by the java libraries, but developers don't need to concern themselves with the innards of this method very often. The HashMap class uses it to associate the specified value with the specified key, but it is all hidden (internal) stuff.
It is also used in referencing objects, so occasionally you will see a toString() method that does not override the toString() method of Object return a value like test@310d42 which is actually a hashCode of the actual reference address (more specifically, the unsigned hexadecimal representation of the hash code of the object). [This message has been edited by Marilyn deQueiroz (edited July 24, 2001).]
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt