Close

Java 8 Streams - LongStream.count Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.LongStreamLongStreamLogicBig

Method:

long count()

This method returns the count of elements in this stream. This is a special case of a reduction and is equivalent to:

mapToLong(e > 1L).sum()

This is a terminal operation.

Examples


package com.logicbig.example.longstream;

import java.util.stream.LongStream;

public class CountExample {

public static void main(String... args) {
LongStream stream = LongStream.range(1, 100);
long count = stream.count();
System.out.println(count);
}
}

Output

99




See Also