108
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.
Signature
The signature of Stream filter() method is given below:
Parameter
predicate: It takes Predicate reference as an argument. Predicate is a functional interface. So, you can also pass lambda expression here.
Return
It returns a new stream.
Java Stream filter() example
In the following example, we are fetching and iterating filtered data.
Output:
90000.0
Java Stream filter() example 2
In the following example, we are fetching filtered data as a list.
Output:
[90000.0]
Next TopicJava Base64 Encode Decode