Java.lang Package Classes

Java Double - hashCode() Method



The java.lang.Double.hashCode() method returns a hash code for this Double object.

Syntax

public int hashCode()

Parameters

No parameter is required.

Return Value

Returns a hash code value for this Double object.

Exception

NA.

Example:

In the example below, the java.lang.Double.hashCode() method returns a hash code for the given Double object.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Double objects
    Double val1 = 10.25;
    Double val2 = -10.25;

    //printing hashcode of the Double objects
    System.out.println("hashCode of the val1 is: " + val1.hashCode()); 
    System.out.println("hashCode of the val2 is: " + val2.hashCode());   
  }
}

The output of the above code will be:

hashCode of the val1 is: 1076133888
hashCode of the val2 is: -1071349760

❮ Java.lang - Double