Optional (Java SE 23 & JDK 23)
-
Method Summary
empty()Returns an empty
Optionalinstance.booleanIndicates whether some other object is "equal to" this
Optional.If a value is present, and the value matches the given predicate, returns an
Optionaldescribing the value, otherwise returns an emptyOptional.If a value is present, returns the result of applying the given
Optional-bearing mapping function to the value, otherwise returns an emptyOptional.get()If a value is present, returns the value, otherwise throws
NoSuchElementException.inthashCode()Returns the hash code of the value, if present, otherwise
0(zero) if no value is present.voidIf a value is present, performs the given action with the value, otherwise does nothing.
voidIf a value is present, performs the given action with the value, otherwise performs the given empty-based action.
booleanisEmpty()If a value is not present, returns
true, otherwisefalse.booleanIf a value is present, returns
true, otherwisefalse.map(Function<? super T, ? extends U> mapper) If a value is present, returns an
Optionaldescribing (as if byofNullable(T)) the result of applying the given mapping function to the value, otherwise returns an emptyOptional.of(T value) Returns an
Optionaldescribing the given non-nullvalue.ofNullable(T value) Returns an
Optionaldescribing the given value, if non-null, otherwise returns an emptyOptional.If a value is present, returns an
Optionaldescribing the value, otherwise returns anOptionalproduced by the supplying function.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
Streamcontaining only that value, otherwise returns an emptyStream.toString()Returns a non-empty string representation of this
Optionalsuitable for debugging.
-
Method Details
-
empty
-
of
-
ofNullable
-
get
-
isPresent
-
isEmpty
-
ifPresent
-
ifPresentOrElse
-
filter
-
map
-
flatMap
-
or
-
stream
-
orElse
-
orElseGet
-
orElseThrow
-
orElseThrow
-
equals
-
hashCode
-
toString
-