Close

Java 8 Streams - LongStream.sequential Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.LongStreamLongStreamLogicBig

Method:

LongStream sequential()

This intermediate operation returns an equivalent stream that is sequential. May return itself, either because the stream was already sequential, or because the underlying stream state was modified to be sequential.

Examples


package com.logicbig.example.longstream;

import java.util.stream.LongStream;

public class SequentialExample {

public static void main(String... args) {

System.out.println("-- default --");
LongStream stream = LongStream.of(4, 7, 9, 11, 13, 17);
stream.forEach(System.out::println);

System.out.println("-- sequential --");
LongStream stream2 = LongStream.of(4, 7, 9, 11, 13, 17)
.sequential();
stream2.forEach(System.out::println);

System.out.println("-- parallel --");
LongStream stream3 = LongStream.of(4, 7, 9, 11, 13, 17)
.parallel();
stream3.forEach(System.out::println);

}
}

Output

-- default --
4
7
9
11
13
17
-- sequential --
4
7
9
11
13
17
-- parallel --
11
13
4
17
9
7




See Also