Java Stream.filter() Method (with Examples)

Last Updated : 6 Apr 2026

Java Stream Filter is a useful method in the Streams API that allows you to select elements based on a condition.

In this chapter, you will learn about the Java Stream filter() method, its usage, benefits, and how it works with stream operations.

What is Java Stream Filter?

The Streams API provides a new abstraction to work with sequences of data. It allows developers to perform operations on collections (like Lists, Sets, and Maps) in a declarative manner, leveraging functional programming concepts.

Streams support various operations, categorized into intermediate and terminal operations. Intermediate operations return a stream, allowing method chaining, while terminal operations produce a result or a side-effect, terminating the stream pipeline.

Java Stream.filter() Method

The filter() method is an intermediate operation that takes a Predicate (a functional interface) as an argument. A Predicate is a functional interface with a single abstract method, test(), which returns a boolean value. The filter() method processes each element of the stream and includes it in the result only if the predicate evaluates to true.

Signature

The signature of Stream filter() method is given below:

Parameter

predicate: It takes a Predicate reference as an argument. Since Predicate is a functional interface, we can also pass a lambda expression.

Return Value

It returns a new stream.

Examples of Stream.filter() Method

Let's understand how the filter() method works in Streams with different examples.

Example 1: Filtering and Iterating Data

In this example, filtered data is fetched and iterated using the filter() method.

In the following example, we are fetching and iterating filtered data.

Compile and Run

Output:

90000.0

Example 2: Collecting Filtered Data into a List

In this example, filtered data is collected into a list using the filter() method.

Output:

[90000.0]