DoubleStream filter(DoublePredicate 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 :
DoubleStream filter(DoublePredicate predicate)
Parameters :
- DoubleStream : A sequence of primitive double-valued elements.
- DoublePredicate : A predicate (boolean-valued function) of one double-valued argument.
Return Value : The function returns the new stream.
Example 1 : filter() method on DoubleStream.
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream = DoubleStream.of( 3.6 , 5.4 , 6.6 , 8.1 , 9.7 );
stream.filter(num -> num > 5.7 )
.forEach(System.out::println);
}
}
|
Example 2 : filter() method on DoubleStream.
import java.util.*;
import java.util.stream.DoubleStream;
class GFG {
public static void main(String[] args)
{
DoubleStream stream = DoubleStream.of( 3.6 , 5.4 , 6.6 , 8.1 , 9.7 );
stream.filter(num -> num / 2.0 > 2.3 )
.forEach(System.out::println);
}
}
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!