Filtering Operations in Stream

This lesson discusses filtering operations in streams.

The filtering operations filters the given stream and returns a new stream, which contains only those elements that are required for the next operation.

filter() method

The Stream interface has a filter() method to filter a stream. This is an intermediate operation. Below is the method definition of filter() method.

Stream filter(Predicate<? super T> predicate)

Parameter -> A predicate to apply to each element to determine if it should be included.

Return Type -> It returns a stream consisting of the elements of this stream that match the given predicate.

Get hands-on with 1200+ tech skills courses.