System.identityHashCode() in Java

System.identityHashCode(): This method is available in java.lang.System class of Java.

Syntax:

int java.lang.System.identityHashCode(Object x)

This method takes one argument of type Object as its parameter. This method returns the same hash code for the given object aswould 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.

Parameters: One parameter is required for this method.

x: object for which the hashCode is to be calculated.

Returns: the hashCode.

Exceptions: NA

Approach

Java

public class SystemidentityHashCode {
    public static void main(String[] args) {

        String key = "os.name";
        System.out.println(System.identityHashCode(key));
    }
}

Output:

1993134103


No comments:

Post a Comment