From the java.lang.*
package, the identityHashCode()
function returns the hash code regarding a defined object (argument value). This hash code is returned through the default function hashCode()
.
static int identityHashCode(Object x)
It takes an argument of Object
type.
x
: This represents the object for which the hash code will be calculated.null
, then a zero value will be returned as a reference.The code to learn about the working of identityHashCode()
is as follows.
// Loaad necessary librariesimport java.lang.*;import java.io.*;public class EdPresso {public static void main(String[] args) throws Exception {// objects of File typeFile f1 = new File("Ali");File f2 = new File("Hamza");File f3 = new File("Mohsin");// returning the HashCodeint hashCode1 = System.identityHashCode(f1);System.out.println(hashCode1);// returning the different HashCode regarding similar filenameint hashCode2 = System.identityHashCode(f2);System.out.println(hashCode2);// returning the HashCodeint hashCode3 = System.identityHashCode(f3);System.out.println(hashCode3);}}