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 {
// w  ww  . j a v  a2s. com
   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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable