in JAVA by
What does the filter() method do? when you use it?

1 Answer

0 votes
The filter method is used to filter elements that satisfy a certain condition that is specified using a Predicate function.

A predicate function is nothing but a function that takes an Object and returns a boolean. For example, if you have a List of Integer and you want a list of even integers.

In this case, you can use the filter to achieve that. You supply a function to check if a number is even or odd, just like this function and filter will apply this to stream elements and filter the elements which satisfy the condition and which doesn't.

Related questions

0 votes
asked Apr 15, 2021 in JAVA by SakshiSharma
0 votes
asked Jan 27, 2020 in JAVA by rahuljain1