Easy java streams

findFirst versus findAny

The 30 second answer

findFirst returns the first element in encounter order when the stream has one. findAny may return any element and is explicitly nondeterministic, which helps parallel performance. Both short-circuit and return Optional, and both throw if the chosen element is null.

findFirst returns the first element in encounter order (if the stream has one). findAny may return any element — "explicitly nondeterministic" — enabling better parallel performance.

Both short-circuit and return Optional. Both throw NullPointerException if the selected element is null.

Sources:

Sources (0)
See inline citations in the answer above.