Java 8 Streams API Find Methods
Internal
Overview
Any of these operations are terminal, in that they return a non-stream result.
Methods
findAny
Returns an Optional describing some element of the stream, or an empty Optional if the stream is empty.
The stream pipeline will be optimized to perform a single pass and finish as soon as a result is found by using short-circuiting.
The behavior of this operation is explicitly nondeterministic; it is free to select any element in the stream. This is to allow for maximal performance in parallel operations; the cost is that multiple invocations on the same source may not return the same result. If a stable result is desired, use findFirst() instead.
Optional<T> findAny()
findFirst
Returns an Optional describing the first element of this stream, or an empty Optional if the stream is empty. If the stream has no encounter order, then any element may be returned.
Optional<T> findFirst()