OptionalDouble orElse(double) method in Java with examples Last Updated : 12 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The orElse(double) method helps us to get the value in this OptionalDouble object. If a value is not present in this OptionalDouble, then this method returns the value passed as the parameter. Syntax: public double orElse(double other) Parameters: This method accepts double the value to be returned, if no value is present. Return value: This method returns the value, if present, otherwise other. Below programs illustrate toString() method: Program 1: Java // Java program to demonstrate // OptionalDouble.orElse(double) method import java.util.OptionalDouble; public class GFG { public static void main(String[] args) { // create a OptionalDouble OptionalDouble opDouble = OptionalDouble.of(452146); // get value using orElse double value = opDouble.orElse(13421); // print double value System.out.println("value: " + value); } } Output:value: 452146.0 Program 2: Java // Java program to demonstrate // OptionalDouble.orElse(double) method import java.util.OptionalDouble; public class GFG { public static void main(String[] args) { // create a OptionalDouble OptionalDouble opDouble = OptionalDouble.empty(); // get value using orElse double value = opDouble.orElse(13421); // print double value System.out.println("value: " + value); } } Output:value: 13421.0 References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#orElse(double) Comment More infoAdvertise with us Next Article OptionalDouble of(double) method in Java with examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-OptionalDouble Practice Tags : Java Similar Reads OptionalDouble orElseGet() method in Java with examples The orElseGet(java.util.function.DoubleSupplier) method helps us to get the value in this OptionalDouble object. If a value is not present in this OptionalDouble, then this method returns the result produced by the supplying function, passed as the parameter Syntax: public double orElseGet(DoubleSup 2 min read 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 1 min read Optional orElse() method in Java with examples The orElse() method of java.util.Optional class in Java is used to get the value of this Optional instance, if present. If there is no value present in this Optional instance, then this method returns the specified value. Syntax: public T orElse(T value) Parameters: This method accepts value as a pa 2 min read OptionalDouble stream() method in Java with examples The stream() method help us to get double value contain by OptionalDouble as DoubleStream.If a value is present, method returns a sequential DoubleStream containing only that value, otherwise returns an empty DoubleStream. Syntax: public DoubleStream stream() Parameters: This method accepts nothing. 1 min read OptionalDouble equals() method in Java with examples OptionalDouble help us to create an object which may or may not contain a Double value. The equals(Object obj) method help us to compare this OptionalDouble object with the passed object as a parameter and it returns true if objects are equal. The other object is considered equal to this OptionalDou 2 min read OptionalDouble empty() method in Java with examples OptionalDouble help us to create an object which may or may not contain a Double value. The empty() method returns an empty OptionalDouble instance. No value is present for this OptionalDouble. So we can say that this method help us to create empty OptionalDouble object. Syntax: public static Option 1 min read Like