IntStream sequential() method in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 03-Apr-2019 12:47:03
Advertisements