Java Integer - hashCode() Method
The java.lang.Integer.hashCode() method returns a hash code for an int value which is compatible with Integer.hashCode().
Syntax
public static int hashCode(int value)
Parameters
value |
Specify the value to hash. |
Return Value
Returns a hash code value for a int value.
Exception
NA.
Example:
In the example below, the java.lang.Integer.hashCode() method returns a hash code for the given int value.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating int values int val1 = 25; int val2 = -25; //printing hashcode of the int values System.out.println("hashCode of the val1 is: " + Integer.hashCode(val1)); System.out.println("hashCode of the val2 is: " + Integer.hashCode(val2)); } }
The output of the above code will be:
hashCode of the val1 is: 25 hashCode of the val2 is: -25
❮ Java.lang - Integer