IntStream sequential() method in Java


The sequential() method of the IntStream class in Java is used to return a sequential IntStream. The syntax is as follows:

IntStream sequential()

First, create an IntStream and elements in a range using the range() method:

IntStream intStream1 = IntStream.range(11, 21);

Now, for a sequential IntStream, use the sequential() method like this:

IntStream intStream2 = intStream1.sequential();

The following is an example to implement IntStream sequential() method in Java:

Example

 Live Demo

import java.util.*;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream1 = IntStream.range(11, 21);
      IntStream intStream2 = intStream1.sequential();
      intStream2.forEach(System.out::println);
   }
}

Output

11
12
13
14
15
16
17
18
19
20

Updated on: 30-Jul-2019

272 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements