Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

OptionalDouble hashCode() method in Java with examples

  • Last Updated : 01 May, 2019

The hashCode() method help us to get the hash code of the value, if Double value is present, otherwise 0 (zero) if no Double value is present in OptionalDouble object.

Syntax:

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

public int hashCode()

Parameters: This method accepts does not accepts any parameter.

Return value: This method returns hash code value of the present value or 0 if no value is present.



Below programs illustrate hashCode() method:

Program 1:




// Java program to demonstrate
// OptionalDouble.hashCode() method
  
import java.util.OptionalDouble;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // create a OptionalDouble instance
        OptionalDouble opDouble
            = OptionalDouble.of(253255.432525);
  
        System.out.println("OptionalDouble: "
                           + opDouble.toString());
  
        // get hashCode value using hashCode()
        System.out.println("HashCode value: "
                           + opDouble.hashCode());
    }
}
Output:
OptionalDouble: OptionalDouble[253255.432525]
HashCode value: 885080309

Program 2:




// Java program to demonstrate
// OptionalDouble.hashCode() method
  
import java.util.OptionalDouble;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // create a OptionalDouble instance
        OptionalDouble opDouble
            = OptionalDouble.empty();
  
        System.out.println("OptionalDouble: "
                           + opDouble.toString());
  
        // get hashCode value using hashCode()
        System.out.println("HashCode value: "
                           + opDouble.hashCode());
    }
}
Output:
OptionalDouble: OptionalDouble.empty
HashCode value: 0

References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#hashCode()




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!