LongStream sequential() method in Java


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

Updated on: 30-Jul-2019

67 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements