OptionalDouble hashCode() method in Java with examples
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:
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()); } } |
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()); } } |
OptionalDouble: OptionalDouble.empty HashCode value: 0
References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#hashCode()
Recommended Posts:
- OptionalDouble toString() method in Java with examples
- OptionalDouble empty() method in Java with examples
- OptionalDouble orElseThrow() method in Java with examples
- OptionalDouble ifPresentOrElse() method in Java with examples
- OptionalDouble equals() method in Java with examples
- OptionalDouble orElseGet() method in Java with examples
- OptionalDouble getAsDouble() method in Java with examples
- OptionalDouble of(double) method in Java with examples
- OptionalDouble isPresent() method in Java with examples
- OptionalDouble stream() method in Java with examples
- OptionalDouble orElseThrow(Supplier) method in Java with examples
- OptionalDouble ifPresent(DoubleConsumer) method in Java with examples
- OptionalDouble orElse(double) method in Java with examples
- Map hashCode() Method in Java with Examples
- Set hashCode() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



