Java provides specialized Stream
s for three types of primitives IntStream
(for int
s), LongStream
(for long
s) and DoubleStream
(for double
s). Besides being optimized implementations for their respective primitives, they also provide several specific terminal methods, typically for mathematical operations. E.g.:
IntStream is = IntStream.of(10, 20, 30);
double average = is.average().getAsDouble(); // average is 20.0