Java 8 Streams Java Java API
java.util.stream.LongStream
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.
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); }}
99