Optional (Java Platform SE 8 )

Modifier and Type
Method and Description

static <T> Optional<T>
empty

Returns an empty Optional instance.

boolean
equalsObject obj)

Indicates whether some other object is “equal to” this Optional.

Optional<T>
filterPredicate<? super T> predicate)

If a value is present, and the value matches the given predicate,
return an Optional describing the value, otherwise return an
empty Optional.

<U> Optional<U>
flatMapFunction<? super T,Optional<U>> mapper)

If a value is present, apply the provided Optional-bearing
mapping function to it, return that result, otherwise return an empty
Optional.

T
get

If a value is present in this Optional, 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
ifPresentConsumer<? super T> consumer)

If a value is present, invoke the specified consumer with the value,
otherwise do nothing.

boolean
isPresent

Return true if there is a value present, otherwise false.

<U> Optional<U>
mapFunction<? super T,? extends U> mapper)

If a value is present, apply the provided mapping function to it,
and if the result is non-null, return an Optional describing the
result.

static <T> Optional<T>
of

Returns an Optional with the specified present non-null value.

static <T> Optional<T>
ofNullable

Returns an Optional describing the specified value, if non-null,
otherwise returns an empty Optional.

T
orElseT other)

Return the value if present, otherwise return other.

T
orElseGetSupplier<? extends T> other)

Return the value if present, otherwise invoke other and return
the result of that invocation.

<X extends Throwable>
T

orElseThrowSupplier<? extends X> exceptionSupplier)

Return the contained value, if present, otherwise throw an exception
to be created by the provided supplier.

String
toString

Returns a non-empty string representation of this Optional suitable for
debugging.