- 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
IntStream anyMatch() method in Java
The anyMatch() method in the IntStream class in Java returns whether any elements of this stream match the provided predicate.
The syntax is as follows
boolean anyMatch(IntPredicate predicate)
To work with the IntStream class in Java, import the following package
import java.util.stream.IntStream;
Here, the predicate parameter is a stateless predicate to apply to elements of this stream.
Create an IntStream and add some elements
IntStream intStream = IntStream.of(20, 40, 60, 80, 100);
Now, use the anyMatch() method to set for a condition. If any of the element match with the condition, TRUE is returned
boolean res = intStream.anyMatch(a -> a < 50);
The following is an example to implement IntStream anyMatch() method in Java
Example
import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(20, 40, 60, 80, 100); boolean res = intStream.anyMatch(a -> a < 50); System.out.println(res); } }
It finds a value less than 50, therefore true is returned
Output
true
Advertisements