LongStream.range() Method in Java



The range() 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 exclusive of the last element.

The syntax is as follows:

static LongStream range(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 range() method in Java:

Example

 Live Demo

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

Output

20
21
22
23
24
Updated on: 2019-07-30T22:30:25+05:30

472 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements