Java Data Type Tutorial - Java System .identityHashCode ( Object x)








Syntax

System.identityHashCode(Object x) has the following syntax.

public static int identityHashCode(Object x)

Example

In the following code shows how to use System.identityHashCode(Object x) method.

public class Main {
//from www.j  a v a  2  s .co m
   public static void main(String[] args) throws Exception {

     String s1 = "java2s";
     String s2 = "java2s.com";
     String s3 = "Java2s.com";

     // returns the HashCode
     int ret1 = System.identityHashCode(s1);
     System.out.println(ret1);
    
     // returns different HashCode for same filename
     int ret2 = System.identityHashCode(s2);
     System.out.println(ret2);
    
     // returns the HashCode    
     int ret3 = System.identityHashCode(s3);
     System.out.println(ret3);
  }
}

The code above generates the following result.