OptionalDouble of(double) method in Java with examples
The of(double) method help us to get an OptionalDouble object which contains a double value which is passed as a parameter to this method.
Syntax:
public static OptionalDouble of(double value)
Parameters: This method accepts a double value as parameter that will be set to the returned OptionalDouble object.
Return value: This method returns an OptionalDouble with the value present.
Below programs illustrate of(double) method:
Program 1:
// Java program to demonstrate // OptionalDouble.of(double) method import java.util.OptionalDouble; public class GFG { public static void main(String[] args) { // Create a OptionalDouble instance // using of() method OptionalDouble opDouble = OptionalDouble.of(45213.246); // Get value of this OptionalDouble instance System.out.println("OptionalDouble: " + opDouble); } } |
OptionalDouble: OptionalDouble[45213.246]
Program 2:
// Java program to demonstrate // OptionalDouble.of(double) method import java.util.OptionalDouble; public class GFG { public static void main(String[] args) { // Create a OptionalDouble instance // using of() method OptionalDouble opDouble = OptionalDouble.of(21438999); // Get value of this OptionalDouble instance System.out.println("OptionalDouble: " + opDouble); } } |
OptionalDouble: OptionalDouble[2.1438999E7]
References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#of(double)
Recommended Posts:
- OptionalDouble equals() method in Java with examples
- OptionalDouble getAsDouble() method in Java with examples
- OptionalDouble orElseThrow() method in Java with examples
- OptionalDouble ifPresentOrElse() method in Java with examples
- OptionalDouble empty() method in Java with examples
- OptionalDouble hashCode() method in Java with examples
- OptionalDouble stream() method in Java with examples
- OptionalDouble orElseGet() method in Java with examples
- OptionalDouble toString() method in Java with examples
- OptionalDouble isPresent() method in Java with examples
- OptionalDouble orElse(double) method in Java with examples
- OptionalDouble ifPresent(DoubleConsumer) method in Java with examples
- OptionalDouble orElseThrow(Supplier) method in Java with examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.numberOfTrailingZeros() 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.



