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.
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 long getAsLong()
Parameters: This method accepts nothing.
Return value: This method returns the value described by this OptionalLong.
Exception: This method throws NoSuchElementException if no value is present
Below programs illustrate getAsLong() method:
OptionalLong: OptionalLong Value in OptionalLong = 445325
OptionalLong: OptionalLong.empty Exception: java.util.NoSuchElementException: No value present