Close

Java 8 Streams - LongStream.range Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.LongStreamLongStreamLogicBig

Method:

static LongStream range(long startInclusive,
                        long endExclusive)

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

Examples


package com.logicbig.example.longstream;

import java.util.stream.LongStream;

public class RangeExample {

public static void main(String... args) {
LongStream longStream = LongStream.range(1, 5);
longStream.forEach(System.out::println);
}
}

Output

1
2
3
4




See Also