- 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
LongStream filter() method in Java
The filter() method in the LongStream class in Java returns a stream consisting of the elements of this stream that match the given predicate.
The syntax is as follows
LongStream filter(LongPredicate predicate)
Here, the parameter predicate is a stateless predicate to apply to each element to determine if it should be included. The LongPredicate represents a predicate (boolean-valued function) of one long-valued argument
To use the LongStream class in Java, import the following package
import java.util.stream.LongStream;
The following is an example to implement LongStream filter() method in Java
Example
import java.util.*; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(10L, 12L, 18L, 20L, 25L, 30L); System.out.println("Filtered elements..."); longStream.filter(a -> a > 20L).forEach(System.out::println); } }
Output
Filtered elements... 25 30
Advertisements