Close

Java 8 Streams - DoubleStream.count Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.DoubleStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.DoubleStreamDoubleStreamLogicBig

Method:

long count()

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

mapToLong(e > 1L).sum()

Examples


package com.logicbig.example.doublestream;

import java.util.stream.DoubleStream;

public class CountExample {

public static void main(String... args) {
DoubleStream ds = DoubleStream.of(1.2, -1.3, 1.4, -1.5, 1.6, -1.7);
long count = ds.count();
System.out.println(count);
}
}

Output

6




See Also