Java 8 Streams API: Filters

Using the Streams API means thinking of your Collections in a different way. We looked at mapping from one type to another in the last post here but in this tutorial I want to show how we take our Stream and only deal with certain values. In this example we want to only deal with Customers with a high credit limit. We do it by applying a filter. Here is all the code to get this to work:

On its own its quite useful but filter should be seen as one of the building blocks when using Streams, just like map. It is when they are put together that complex logic from pre-Java 8 can be made simpler. The only issue is the learning curve but it is worth it.