C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Range: This has an exclusive end. So the second argument is not included in the IntStream that is returned.
RangeClosed: This has an inclusive (closed) end. If the second argument is 15, the 15 is included.
Java program that uses IntStream.range
import java.util.Arrays;
import java.util.stream.IntStream;
public class Program {
public static void main(String[] args) {
// Use IntStream.range.
IntStream range1 = IntStream.range(10, 15);
System.out.println("Range(10, 15): " +
Arrays.toString(range1.toArray()));
// Use IntStream.rangeClosed.
IntStream range2 = IntStream.rangeClosed(10, 15);
System.out.println("RangeClosed(10, 15): " +
Arrays.toString(range2.toArray()));
}
}
Output
Range(10, 15): [10, 11, 12, 13, 14]
RangeClosed(10, 15): [10, 11, 12, 13, 14, 15]