LongStream sequential() method in Java

Java 8Object Oriented ProgrammingProgramming

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 −

Example

 Live Demo

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);
   }
}

Output

50
70
100
150
200
300
raja
Published on 27-Mar-2019 10:42:01
Advertisements