> For the complete documentation index, see [llms.txt](https://avbravo-2.gitbook.io/java-8/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://avbravo-2.gitbook.io/java-8/chapter1/filter.md).

# filter

<https://zeroturnaround.com/rebellabs/java-8-explained-applying-lambdas-to-java-collections/>

```java
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/>
