Java8提供的Stream支持两种操作
一种是中间操作,如filter, map, skip, limit......中间操作不会消耗流,只是将一个流转换成另外一个流,类似于流水线。
而终端操作会消耗流,以产生一个最终结果,终端操作完成后,流就被消耗了,不可再调用相关操作流的方法。...查找流中的最大值和最小值
public static void main(String[] args) {
Random random = new Random();
Optional x));
System.out.println("平均值为: " + avg);
}
结果:
求和结果: 514905
平均值为: 514.905
在需要同时获取流中元素的个数...10, country=中国),AppleStream(weight=20, country=米国),AppleStream(weight=30, country=韩国)】
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20