- 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
LongStream anyMatch() method in Java
The anyMatch() method of the LongStream class in Java returns whether any elements of this stream match the provided predicate.
The syntax is as follows.
boolean anyMatch(LongPredicate predicate)
Here, the parameter predicate is the stateless predicate to apply to elements of this stream. The LongPredicate represents a predicate 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 anyMatch() method in Java.
Example
import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(100L, 150L, 200L, 300L, 400L, 500L); boolean res = longStream.anyMatch(a -> a > 350L); System.out.println("Do any of the element match the predicate? "+res); } }
Here is the output. It returns TRUE since atleast one of the element match the predicate mentioned in the anyMatch() method.
Output
Do any of the element match the predicate? true
Advertisements