Close

Java 8 Streams - DoubleStream.forEachOrdered Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.DoubleStream

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

Method:

void forEachOrdered(DoubleConsumer action)

This terminal operation performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order.

Examples


package com.logicbig.example.doublestream;

import java.util.stream.DoubleStream;

public class ForEachOrderedExample {

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.forEachOrdered(System.out::println);

System.out.println("-- parallel --");
DoubleStream ds2 = DoubleStream.of(1.0, 1.2, 2.0, 2.4, 3.0);
ds2.parallel()
.forEachOrdered(System.out::println);
}
}

Output

-- sequential --
1.0
1.2
2.0
2.4
3.0
-- parallel --
1.0
1.2
2.0
2.4
3.0




See Also