Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Long.hashCode() method is used to return 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 below example, the java.lang.Long.hashCode() method is used to return 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 = 1025;
    long val2 = -1025;

    //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