OptionalInt

public final class OptionalInt extends Object

A container object which may or may not contain a int value. If a value is present, isPresent() will return true and getAsInt() will return the value.

Additional methods that depend on the presence or absence of a contained value are provided, such as orElse() (return a default value if value not present) and ifPresent() (execute a block of code if the value is present).

Public Method Summary

static OptionalInt
empty()
Returns an empty OptionalInt instance.
boolean
equals(Object obj)
Indicates whether some other object is "equal to" this OptionalInt.
int
getAsInt()
If a value is present in this OptionalInt, returns the value, otherwise throws NoSuchElementException.
int
hashCode()
Returns the hash code value of the present value, if any, or 0 (zero) if no value is present.
void
ifPresent(IntConsumer consumer)
Have the specified consumer accept the value if a value is present, otherwise do nothing.
boolean
isPresent()
Return true if there is a value present, otherwise false.
static OptionalInt
of(int value)
Return an OptionalInt with the specified value present.
int
orElse(int other)
Return the value if present, otherwise return other.
int
orElseGet(IntSupplier other)
Return the value if present, otherwise invoke other and return the result of that invocation.
<X ex