- 映射
- 排序
- 终端操作会从流的流水线生成结果 。其结果可以是任何不是流的值,例如:List、Integer,甚至是 void。
- 流进行了终止操作后,不能再次使用 。
- 匹配与查找
- 归约
- 收集
方法返回类型作用调用toListList把流中元素收集到ListList emps= list.stream().collect(Collectors.toList());toSetSet把流中元素收集到SetSet emps= list.stream().collect(Collectors.toSet());toCollectionCollection把流中元素收集到创建的集合Collection emps =list.stream().collect(Collectors.toCollection(ArrayList::new));countingLong计算流中元素的个数long count = list.stream().collect(Collectors.counting());summingIntInteger对流中元素的整数属性求和intaveragingIntDouble计算流中元素Integer属性的平均值double avg = list.stream().collect(Collectors.averagingInt(Employee::getSalary));summarizingIntIntSummaryStatistics收集流中Integer属性的统计值 。如:平均值int SummaryStatisticsiss= list.stream().collect(Collectors.summarizingInt(Employee::getSalary));joiningString连接流中每个字符串String str= list.stream().map(Employee::getName).collect(Collectors.joining());maxByOptional根据比较器选择最大值Optionalmax= list.stream().collect(Collectors.maxBy(comparingInt(Employee::getSalary)));minByOptional根据比较器选择最小值Optional min = list.stream().collect(Collectors.minBy(comparingInt(Employee::getSalary)));reducing归约产生的类型从一个作为累加器的初始值开始,利用BinaryOperator与流中元素逐个结合,从而归约成单个值int total=list.stream().collect(Collectors.reducing(0, Employee::getSalar,Integer::sum));collectingAndThen转换函数返回的类型包裹另一个收集器,对其结果转换函数int how= list.stream().collect(Collectors.collectingAndThen(Collectors.toList(), List::size));groupingByMap<K, List>根据某属性值对流分组,属性为K,结果为VMap<Emp.Status, List> map=list.stream().collect(Collectors.groupingBy(Employee::getStatus));partitioningByMap<Boolean, List>根据true或false进行分区Map<Boolean,List> vd = list.stream().collect(Collectors.partitioningBy(Employee::getManage));
经验总结扩展阅读
- java 入土--集合详解
- 4 Java I/O:AIO和NIO中的Selector
- 2023年10月5日搬新家好不好 2023年10月5日是搬新家吉日吗
- 2023年10月5日乔迁新居吉日一览表 2023年农历八月廿一乔迁新居吉日
- 不同阶段婴儿的奶瓶怎么选择
- 新鲜的黄瓜冷冻起来可以吗
- 有感 11月10日2时47分新疆乌鲁木齐市乌鲁木齐县发生2.5级地震
- 2023年2月8日搬新家好不好 2023年农历正月十八宜搬新家吗
- oppowatch连接手机_oppowatch怎么连接手机
- 2023年2月8日是乔迁新居的黄道吉日吗 2023年农历正月十八乔迁新居吉日