- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DoubleStream filter() method in Java
The filter() method of the DoubleStream class returns a stream consisting of the elements of this stream that match the given predicate.
The syntax is as follows
DoubleStream filter(DoublePredicate predicate)
The parameter predicate is a stateless predicate to apply to each element to determine if it should be included.
To use the DoubleStream class in Java, import the following package
import java.util.stream.DoubleStream;
Create a DoubleStream and add some elements
DoubleStream doubleStream = DoubleStream.of(20.5, 35.7, 50.8, 67.9, 89.8, 93.1);
Filter and display the element equal to a 50.8, if it’s present
doubleStream.filter(a -> a == 50.8)
The following is an example to implement DoubleStream filter() method in Java
Example
import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(20.5, 35.7, 50.8, 67.9, 89.8, 93.1); doubleStream.filter(a -> a == 50.8).forEach(System.out::println); } }
Output
50.8
Advertisements