Pages

Thursday, February 14, 2013

Hash Code of Objects in Java


JVM allocated memory for the objects when they are initialized in the main() method.
HashCode is a unique identity given by the JVM to each and every object which is not normally used.


Object class contains the function hashCode() to retrieve the unique ID for the object generated by the JVM.

Important Points :

hashCode() returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

Alternative Method : identityHashCode(Object x) from System Class.

Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode().The hash code for the null reference is zero.

Example Program : http://pastie.org/6165123

0 comments:

Post a Comment