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 ...