- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
The filter() method in Java is part of the Stream API introduced in Java 8. It is used to filter elements of a stream based on a given predicate. This method creates a new stream containing only the elements that satisfy the predicate condition.
Example: Filter Numbers Divisible by 5
import java.util.Arrays;import java.util.List;public class Main {public static void main(String[] args) {List<Integer> numbers = Arrays.asList(3, 4, 6, 12, 20);numbers.stream().filter(num -> num % 5 == 0) // Filter numbers divisible by 5.forEach(System.out::println); // Output: 20}}Copied!✕CopyHow It Works
The filter() method is an intermediate operation, meaning it does not execute immediately but waits until a terminal operation (like forEach or collect) is invoked. It uses a Predicate functional interface to test each element.
Example: Filter Strings Ending with 's'
Stream filter() in Java with examples - GeeksforGeeks
Jul 9, 2024 · Stream filter (Predicate predicate) returns a stream consisting of the elements of this stream that match the given predicate. This is an intermediate operation.
See results only from geeksforgeeks.orgSign In
Stream filter (Predicate predicate) returns a stream consisting of the elements of this stream that match the given predicate. This is an intermediate operation.
Java Stream Filter with Lambda Expression - Baeldung
- Published: Dec 12, 2018
Stream (Java Platform SE 8 ) - Oracle Help Center
- filter. Stream<T> filter(Predicate<? super T> predicate) Returns a stream consisting of the …
- map. <R> Stream<R> map(Function<? super T,? extends R> mapper) Returns a stream consisting …
- mapToInt. IntStream mapToInt(ToIntFunction<? super T> mapper) Returns an IntStream consisting …
- mapToLong. LongStream mapToLong(ToLongFunction<? super T> mapper) Returns a LongStream …
- mapToDouble. DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper) Returns a …
How to Filter a Collection Using Streams in Java?
Jun 9, 2025 · By applying the concepts and techniques discussed in this article, you can become proficient in using Java streams to filter collections and improve …
Java Stream filter - filtering Java streams - ZetCode
May 25, 2025 · Java Stream filter tutorial provides a detailed guide on how to use the filter method to efficiently process and filter elements in Java streams. Learn about predicate functions, lambda …
Searches you might like
Java Stream Filter Example: A Comprehensive Guide
Jan 16, 2026 · This blog post will explore the fundamental concepts of the Java Stream `filter` method, its usage, common practices, and best-practices to help you gain an in-depth understanding and use …
Java Stream filter () Example
This tutorial explains how to use the filter () method in the Java Stream API. The filter () method is an intermediate operation that tests each element of a stream to see if it matches a given predicate.
Java’s Stream.filter () Method Explained - Medium
Jul 28, 2024 · Learn how to use Java's Stream.filter () method to process collections efficiently, with practical examples on filtering user data and …
Java 8 Stream Tutorial - GeeksforGeeks
3 days ago · Java 8 introduced the Stream API, which allows developers to process collections of data in a functional and declarative way. Streams make it easier to …
The Java Stream API Tutorial - Baeldung
Oct 5, 2023 · Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping …