filter
https://zeroturnaround.com/rebellabs/java-8-explained-applying-lambdas-to-java-collections/
Filter
Filtering a stream of data is the first natural operation that we would need. Stream interface exposes a filter method that takes in a Predicate (http://javadocs.techempower.com/jdk18/api/java/util/function/Predicate.html ) SAM that allows us to use lambda expression to define the filtering criteria:
List<Person> persons = …
Stream<Person> personsOver18 = persons.stream().filter(p -> p.getAge() > 18);
Now the thing is that often you want to filter a List just like in the example above. Then you can easily convert the list to a stream, filter and collect the results back to a list if necessary.
https://www.mkyong.com/java8/java-8-streams-filter-examples/
Last updated
Was this helpful?