Filter List Java
Stream filter() in Java with examplesStream filter(Predicate predicate) returns a stream consisting of the elements of this stream that match the given predicate. This is an intermediate operation. These operations are always lazy i.e, executing an intermediate operation such as filter() does not actually perform any filtering, but instead creates a new stream that, when traversed, contains the elements of the initial stream that match the given predicate. Syntax : Stream<T> filter(Predicate<? super T> predicate) Where, Stream is an interface and T is the type of the input to the predicate. The function returns the new stream.Example 1 : filter() method with operation of filtering out the elements divisible by 5.
Output : 20Example 2 : filter() method with operation of filtering out the elements with upperCase letter at index 1.
Output : Example 3 : filter() method with operation of filtering out the elements ending with s.
Output : Geeks GeeksforGeeks
Article Tags :
Java
Java - util package Java-Functions java-stream Java-Stream interface Practice Tags :
Java
Read Full Article
|