IntStream range(int startInclusive, int endExclusive) example

Description

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

Syntax

range has the following syntax.


static IntStream range(int startInclusive,   int endExclusive)

Example

The following example shows how to use range.


import java.util.stream.IntStream;
//  w  ww .j a va2 s .  c  om
public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.range(1,7);
    i.forEach(System.out::println); 
    
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder