LongStream rangeClosed() method in Java

Java 8Object Oriented ProgrammingProgramming

The rangeClosed() method of the LongStream class in Java returns a sequential ordered LongStream from startInclusive to endExclusive by an incremental step of 1. This is inclusive of the initial element and the last element.

The syntax is as follows −

static LongStream rangeClosed(long startInclusive, long endExclusive)

Here, startInclusive is the first value, whereas the endExclusive is the last.

To use the LongStream class in Java, import the following package −

import java.util.stream.LongStream;

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

Example

 Live Demo

import java.util.stream.LongStream;

public class Demo {
   public static void main(String[] args) {
      LongStream longStream = LongStream.rangeClosed(20L, 25L);
      longStream.forEach(System.out::println);
   }
}

Output

20
21
22
23
24
25
raja
Published on 27-Mar-2019 14:27:15
Advertisements