OptionalInt help us to create an object which may or may not contain a int value. The
getAsInt() method returns value If a value is present in OptionalInt object, otherwise throws
NoSuchElementException.
Syntax:
public int getAsInt()
Parameters: This method accepts nothing.
Return value: This method returns the value described by this OptionalInt.
Exception: This method throws
NoSuchElementException if no value is present
Below programs illustrate getAsInt() method:
Program 1:
Output:
OptionalInt: OptionalInt[45]
Value in OptionalInt = 45
Program 2: