Java Streams - LongStream range(long startInclusive, long endExclusive) example








LongStream range(long startInclusive, long endExclusive) returns a sequential ordered LongStream from startInclusive (inclusive) to endExclusive (exclusive) by an incremental step of 1.

Syntax

range has the following syntax.

static LongStream range(long startInclusive,  long endExclusive)

Example

The following example shows how to use range.

import java.util.stream.LongStream;

public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.range(1L, 5L);

    b.forEach(System.out::println);
  }
}

The code above generates the following result.