- 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 count() method in Java
The count() method of the IntStream class in Java returns the count of elements in this stream
The syntax is as follows
long count()
First, create an IntStream and add some elements
IntStream intStream = IntStream.of(30, 13, 67, 56, 89, 99, 76, 56);
Now, get the count of elements of the stream using the count() method
long num = intStream.count();
The following is an example to implement IntStream count() method in Java
Example
import java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(30, 13, 67, 56, 89, 99, 76, 56); long num = intStream.count(); System.out.println("Count of elements in the stream: "+num); } }
Output
Count of elements in the stream: 8
Advertisements