From the course: Functional Programming with Java

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Filter in Java

Filter in Java - Java Tutorial

From the course: Functional Programming with Java

Start my 1-month free trial

Filter in Java

- [Instructor] The next important stream function we're going to look at here is called filter. Filter is used when you want to find all the elements in an array or list that fit some kind of criteria. So for example, if we have a list of numbers and we want to get all the numbers from it that are even, or if we have a list of employee objects, and we want to find the employees from this list that make more than a certain amount per year. These are some examples of things that the filter function can help us with. So the syntax of filter is similar to map. We convert our list data into a stream, and then we can call the filter function with a function object as an argument. The main difference between filter and map is the type of function that we pass to it. You see, with map, we pass in a function that returns a value for each element in our stream. And the return value of this function represents what that element becomes after the element is processed. Now, on the other hand, for…

Contents