Java Integer hashCode() method
The hashCode() method of Java Integer class returns a hash code for this Integer. Syntax
- public int hashCode()
- public static int hashCode(int value)
public class JavaIntegerHashCodeExample1 { public static void main(String[] args) { Integer val=45; //returns a hash code for this Integer int hash=val.hashCode(); System.out.println("Hash code for "+val+" is "+hash); Integer va11=78; System.out.println("Hash code for "+va11+" is "+va11.hashCode()); } }Output
Hash code for 45 is 45 Hash code for 78 is 78Example 2
public class JavaIntegerHashCodeExample2 { public static void main(String[] args) { Integer val=45; //calling a static hash code method int hash=Integer.hashCode(val); System.out.println("Hash code for "+val+" is "+hash); Integer va11=78; System.out.println("Hash code for "+va11+" is "+Integer.hashCode(va11)); } }Output
Hash code for 45 is 45 Hash code for 78 is 78