Close

Java 8 Streams - IntStream.rangeClosed Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.IntStreamIntStreamLogicBig

Method:

static IntStream rangeClosed(int startInclusive, int endInclusive)

Returns a sequential ordered IntStream from startInclusive (inclusive) to endInclusive (inclusive) by an incremental step of 1.


Examples


package com.logicbig.example.intstream;

import java.util.stream.IntStream;

public class RangeClosedExample {
//static IntStream rangeClosed(int startInclusive,
// int endInclusive)

public static void main(String... args) {
System.out.println("-- rangeClosed --");
IntStream intStream = IntStream.rangeClosed(1, 5);
intStream.forEach(System.out::println);

System.out.println("-- range --");
intStream = IntStream.range(1, 5);
intStream.forEach(System.out::println);

}
}

Output

-- rangeClosed --
1
2
3
4
5
-- range --
1
2
3
4




See Also