From the course: Data Science for Java Developers

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Filtering

Filtering

- [Instructor] The next data manipulation method we're going to take a look at is the filter method. So the filter method is used in a very similar way to the map method that we just saw except instead of transforming each of the items in a list, it's actually used to make sure we only get a certain subset of the items in the list depending on some sort of criteria that we can specify. So let me show you what I mean, let's say that maybe we want to get all of the words in our words list here that is longer than four characters just as an example. Well, in that case, what we could do and I'm going to delete all these map examples here, is we could say List<String> and we'd say something like long words equals words and convert it into a stream here. And then we'd say .filter and we pass a function of filter in a very similar way to what we did with map except the function that we pass to filter is going to return either…

Contents