IntStream.range()和IntStream.rangeClosed区别

其实区别就是开区间和闭区间的区别
如:[1,20)和[1,20]的区别
例子:

//3.创建数字流
        IntStream.of(1, 2, 3);//返回一个intStream
        IntStream.range(1,20).forEach(i-> System.out.print(i+","));//返回一个1-19的数字流
        System.out.println();
        IntStream.rangeClosed(1,20).forEach(i-> System.out.print(i+","));//返回的一个1-20的数字流

结果:

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,

你可能感兴趣的:(JAVA,lambda,InSteam,range(),rangeClosed)