The reason these operators return an Optional is that, generally, there may be not a single element emitted (the Stream object is empty). An Optional object allows checking for the presence of the value before committing to getting it, thus avoiding unexpected behavior.
The post Java streams 22. FindAny(), findFirst(), max(), min() appeared first on Nick Samoylov, programmer and writer.
Published on April 09, 2020 20:31