Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
