Java Stream Filter
Java stream provides a method filter() to filter stream elements on the basis of given predicate. Suppose you want to get only even elements of your list then you can do this easily with the help of filter method.
This method takes predicate as an argument and returns a stream of consisting of resulted elements.
The signature of Stream filter() method is given below:
predicate: It takes Predicate reference as an argument. Predicate is a functional interface. So, you can also pass lambda expression here.
It returns a new stream.
Java Stream filter() example
In the following example, we are fetching and iterating filtered data.
Java Stream filter() example 2
In the following example, we are fetching filtered data as a list.