IntStream rangeClosed() method in Java

Java 8ProgrammingObject Oriented Programming

The rangeClosed() class in the IntStream class returns a sequential ordered IntStream from startInclusive to endInclusive by an incremental step of 1. This includes both the startInclusive and endInclusive values.

The syntax is as follows

static IntStream rangeClosed(int startInclusive, int endInclusive)

Here, startInclusive is the value including the first value and endInclusive is the value indicating the last value. To work with the IntStream class in Java, import the following package

import java.util.stream.IntStream;

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

Example

 Live Demo

import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.rangeClosed(15, 25);
      intStream.forEach(System.out::println);
   }
}

Output

15
16
17
18
19
20
21
22
23
24
25
raja
Published on 26-Mar-2019 14:57:02
Advertisements