There's more...

In this recipe we used an interface and a class provided by the Java API. The Predicate interface is a functional interface that is usually expressed as a lambda expression. This expression will receive an element of Stream and return a Boolean value. If you want to implement a class that implements this interface, you only have to implement the test() method that receives an object of the parameterized type and returns a Boolean value. The interface defines more methods, but they have a default implementation.

The Optional class is used when a terminal operation of Stream may or may not return a value. In this way, Java guarantees that the operation will always return a value, the Optional object, that may have a value we ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.