OptionalLong

public final class OptionalLong extends Object

A container object which may or may not contain a long value. If a value is present, isPresent() will return true and getAsLong() 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 OptionalLong
empty()
Returns an empty OptionalLong instance.
boolean
equals(Object obj)
Indicates whether some other object is "equal to" this OptionalLong.
long
getAsLong()
If a value is present in this OptionalLong, 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(LongConsumer 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 OptionalLong
of(long value)
Return an OptionalLong with the specified value present.
long
orElse(long other)
Return the value if present, otherwise return other.
long
orElseGet(LongSupplier other)
Return the value if present, otherwise invoke other and return the result of that invocation.