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