The sequential() method of the LongStream class in Java returns an equivalent stream that is sequential.
The syntax is as follows −
LongStream sequential()
To use the LongStream class in Java, import the following package −
import java.util.stream.LongStream;
Create a LongStream and add some elements −
LongStream longStream = LongStream.of(50L, 70L, 100L, 150L, 200L, 300L);
Now, return an equivalent stream that is sequential −
LongStream res = longStream.sequential();
The following is an example to implement LongStream sequential() method in Java −
import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(50L, 70L, 100L, 150L, 200L, 300L); LongStream res = longStream.sequential(); res.forEach(System.out::println); } }
50 70 100 150 200 300