- Experiment with the range(int startInclusive, int endInclusive) and rangeClosed(int startInclusive, int endInclusive) methods of the IntStream and LongStream interfaces:
IntStream.range(1,3).forEach(System.out::print); //prints: 12LongStream.range(1,3).forEach(System.out::print); //prints: 12IntStream.rangeClosed(1,3).forEach(System.out::print); // 123LongStream.rangeClosed(1,3).forEach(System.out::print); // 123
As you can see, the difference between the range() and rangeClosed() methods is the exclusion or inclusion of the value passed in as the second parameter. This also leads to the following results in the case where both parameters have the same value:
IntStream.range(3,3).forEach(System.out::print); //prints:LongStream. ...