Java 8 Streams Java Java API
java.util.stream.DoubleStream
void forEach(DoubleConsumer action)
This terminal operation performs an action for each element of this stream.
For parallel stream, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism.
package com.logicbig.example.doublestream;import java.util.stream.DoubleStream;public class ForEachExample { public static void main(String... args) { System.out.println("-- sequential --"); DoubleStream ds = DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0); ds.forEach(System.out::println); System.out.println("-- parallel --"); DoubleStream ds2 = DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0); ds2.parallel() .forEach(System.out::println); }}
-- sequential --1.01.22.02.43.0-- parallel --2.03.01.21.02.4