OptionalDouble getAsDouble() method in Java with examples Last Updated : 30 Jul, 2019 Comments Improve Suggest changes Like Article Like Report OptionalDouble help us to create an object which may or may not contain a double value. The getAsDouble() method returns value If a value is present in OptionalDouble object, otherwise throws NoSuchElementException. Syntax: public double getAsDouble() Parameters: This method accepts nothing. Return value: This method returns the value described by this OptionalDouble. Exception: This method throws NoSuchElementException if no value is present Below programs illustrate getAsDouble() method: Program 1: Java // Java program to demonstrate // OptionalDouble.getAsDouble() method import java.util.OptionalDouble; public class GFG { public static void main(String[] args) { // Create an OptionalDouble instance OptionalDouble opDouble = OptionalDouble.of(44356.455); System.out.println("OptionalDouble: " + opDouble.toString()); // Get value in this instance // using getAsDouble() System.out.println("Value in OptionalDouble = " + opDouble.getAsDouble()); } } Output: OptionalDouble: OptionalDouble[44356.455] Value in OptionalDouble = 44356.455 Program 2: Java // Java program to demonstrate // OptionalDouble.getAsDouble() method import java.util.OptionalDouble; public class GFG { public static void main(String[] args) { try { // Create an OptionalDouble instance OptionalDouble opDouble = OptionalDouble.empty(); System.out.println("OptionalDouble: " + opDouble.toString()); // Get value in this instance // using getAsDouble() System.out.println("Value in OptionalDouble = " + opDouble.getAsDouble()); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: OptionalDouble: OptionalDouble.empty Exception: java.util.NoSuchElementException: No value present References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#getAsDouble() Comment More infoAdvertise with us Next Article OptionalDouble ifPresentOrElse() 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 ifPresentOrElse() method in Java with examples The ifPresentOrElse(java.util.function.DoubleConsumer, java.lang.Runnable) method helps us to perform the specified DoubleConsumer action the value of this OptionalDouble object. If a value is not present in this OptionalDouble, then this method performs the given empty-based Runnable emptyAction, p 2 min read OptionalDouble ifPresentOrElse() method in Java with examples The ifPresentOrElse(java.util.function.DoubleConsumer, java.lang.Runnable) method helps us to perform the specified DoubleConsumer action the value of this OptionalDouble object. If a value is not present in this OptionalDouble, then this method performs the given empty-based Runnable emptyAction, p 2 min read Optional get() method in Java with examples The get() method of java.util.Optional class in Java is used to get the value of this Optional instance. If there is no value present in this Optional instance, then this method throws NullPointerException. Syntax: public T get() Parameters: This method do not accept any parameter. Return value: Thi 2 min read Optional get() method in Java with examples The get() method of java.util.Optional class in Java is used to get the value of this Optional instance. If there is no value present in this Optional instance, then this method throws NullPointerException. Syntax: public T get() Parameters: This method do not accept any parameter. Return value: Thi 2 min read OptionalLong getAsLong() method in Java with examples OptionalLong help us to create an object which may or may not contain a long value. The getAsLong() method returns value If a value is present in OptionalLong object, otherwise throws NoSuchElementException. Syntax: public long getAsLong() Parameters: This method accepts nothing. Return value: This 2 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 Like