Uses of Class
java.util.Optional
-
Packages that use Optional Package Description java.util Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).java.util.stream Classes to support functional-style operations on streams of elements, such as map-reduce transformations on collections. -
-
Uses of Optional in java.util
Methods in java.util that return Optional Modifier and Type Method and Description static <T> Optional<T>
Optional. empty()
Returns an emptyOptional
instance.Optional<T>
Optional. filter(Predicate<? super T> predicate)
If a value is present, and the value matches the given predicate, return anOptional
describing the value, otherwise return an emptyOptional
.<U> Optional<U>
Optional. flatMap(Function<? super T,Optional<U>> mapper)
If a value is present, apply the providedOptional
-bearing mapping function to it, return that result, otherwise return an emptyOptional
.<U> Optional<U>
Optional. map(Function<? 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 anOptional
describing the result.static <T> Optional<T>
Optional. of(T value)
Returns anOptional
with the specified present non-null value.static <T> Optional<T>
Optional. ofNullable(T value)
Returns anOptional
describing the specified value, if non-null, otherwise returns an emptyOptional
.Method parameters in java.util with type arguments of type Optional Modifier and Type Method and Description <U> Optional<U>
Optional. flatMap(Function<? super T,Optional<U>> mapper)
If a value is present, apply the providedOptional
-bearing mapping function to it, return that result, otherwise return an emptyOptional
. -
Uses of Optional in java.util.stream
Methods in java.util.stream that return Optional Modifier and Type Method and Description Optional<T>
Stream. findAny()
Returns anOptional
describing some element of the stream, or an emptyOptional
if the stream is empty.Optional<T>
Stream. findFirst()
Returns anOptional
describing the first element of this stream, or an emptyOptional
if the stream is empty.Optional<T>
Stream. max(Comparator<? super T> comparator)
Returns the maximum element of this stream according to the providedComparator
.Optional<T>
Stream. min(Comparator<? super T> comparator)
Returns the minimum element of this stream according to the providedComparator
.Optional<T>
Stream. reduce(BinaryOperator<T> accumulator)
Performs a reduction on the elements of this stream, using an associative accumulation function, and returns anOptional
describing the reduced value, if any.Methods in java.util.stream that return types with arguments of type Optional Modifier and Type Method and Description static <T> Collector<T,?,Optional<T>>
Collectors. maxBy(Comparator<? super T> comparator)
Returns aCollector
that produces the maximal element according to a givenComparator
, described as anOptional<T>
.static <T> Collector<T,?,Optional<T>>
Collectors. minBy(Comparator<? super T> comparator)
Returns aCollector
that produces the minimal element according to a givenComparator
, described as anOptional<T>
.static <T> Collector<T,?,Optional<T>>
Collectors. reducing(BinaryOperator<T> op)
Returns aCollector
which performs a reduction of its input elements under a specifiedBinaryOperator
.
-
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2022, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.