Type Parameters:
T - the type of value

  • Method Summary

    empty()

    Returns an empty Optional instance.

    boolean

    Indicates whether some other object is "equal to" this Optional.

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

    If a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional.

    get()

    If a value is present, returns the value, otherwise throws NoSuchElementException.

    int

    hashCode()

    Returns the hash code of the value, if present, otherwise 0 (zero) if no value is present.

    void

    If a value is present, performs the given action with the value, otherwise does nothing.

    void

    If a value is present, performs the given action with the value, otherwise performs the given empty-based action.

    boolean

    isEmpty()

    If a value is not present, returns true, otherwise false.

    boolean

    isPresent()

    If a value is present, returns true, otherwise false.

    map(Function<? super T, ? extends U> mapper)

    If a value is present, returns an Optional describing (as if by ofNullable(T)) the result of applying the given mapping function to the value, otherwise returns an empty Optional.

    of(T value)

    Returns an Optional describing the given non-null value.

    ofNullable(T value)

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

    If a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function.

    orElse(T other)

    If a value is present, returns the value, otherwise returns other.

    If a value is present, returns the value, otherwise returns the result produced by the supplying function.

    If a value is present, returns the value, otherwise throws NoSuchElementException.

    orElseThrow(Supplier<? extends X> exceptionSupplier)

    If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.

    stream()

    If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.

    toString()

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

    Methods declared in class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Creates and returns a copy of this object.

    protected void

    Deprecated, for removal: This API element is subject to removal in a future version.

    Returns the runtime class of this Object.

    final void

    Wakes up a single thread that is waiting on this object's monitor.

    final void

    Wakes up all threads that are waiting on this object's monitor.

    final void

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

    final void

    wait(long timeoutMillis)

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

    final void

    wait(long timeoutMillis, int nanos)

    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

  • Method Details

    • empty

    • of

    • ofNullable

    • get

    • isPresent

    • isEmpty

    • ifPresent

    • ifPresentOrElse

    • filter

    • map

    • flatMap

    • or

    • stream

    • orElse

    • orElseGet

    • orElseThrow

    • orElseThrow

    • equals

    • hashCode

    • toString