![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 count() method in Java
The count() method of the LongStream class in Java is used to return the count of elements in this stream.
The syntax is as follows.
long count()
To use the LongStream class in Java, import the following package.
import java.util.stream.LongStream;
Create a LongStream and add some elements.
LongStream longStream = LongStream.of(50L, 30L, 80L, 40L, 15L, 60L);
Now, get the count of elements.
longStream.count()
The following is an example to implement LongStream count() method in Java.
Example
import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(50L, 30L, 80L, 40L, 15L, 60L); System.out.println("The number of elements in the stream = "+longStream.count()); } }
Output
The number of elements in the stream = 6
Advertisements