OptionalDouble orElseThrow() method in Java with examples
OptionalDouble help us to create an object which may or may not contain a Double value. The orElseThrow() method help us to get the double value. If double value is not present then this method will throw NoSuchElemenrException.
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 Double orElseThrow()
Parameters: This method accepts nothing.
Return value: This method returns the Double value described by this OptionalDouble.
Exception: This method throws NoSuchElementException if no value is present
Below programs illustrate orElseThrow() method:
double Value extracted using orElseThrow() = 134.1
Exception thrown : java.util.NoSuchElementException: No value present