///根据name分组
Map> collect =listUser.stream().collect(Collectors.groupingBy(UserInfo::getName));
System.out.println(JSON.toJSONString(collect));///Collectors.averagingDouble 取出平均值
Optional.ofNullable(list.stream().collect(Collectors.averagingDouble(Dish::getOalories)))
.ifPresent(System.out::println);///collectingAndThen 对结果进行处理
Optional.ofNullable(list.stream().collect(Collectors.collectingAndThen(Collectors.averagingDouble(Dish::getOalories),(a->"平均值:"+a))))
.ifPresent(System.out::println);
List dishList = list.stream().filter(d ->d.getType().equals(Dish.Type.OTHER)).collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));//dishList.add(new Dish("salmon", false, 550, Dish.Type.FISH));
System.out.println(JSON.toJSONString(dishList));///打印集合个数
Optional.ofNullable(list.stream().collect(Collectors.counting())).ifPresent(System.out::println);///{OTHER=4, MEAT=3, FISH=2} 分组之后统计分组的个数
Optional.ofNullable(list.stream().collect(Collectors.groupingBy(Dish::getType,Collectors.counting()))).ifPresent(System.out::println);///分组之后 求出平均值 并且返回的TreeMap
Optional.ofNullable(list.stream().collect(Collectors.groupingBy(Dish::getType, TreeMap::new,Collectors.averagingDouble(Dish::getOalories)))).ifPresent(System.out::println);///DoubleSummaryStatistics 统计集合的值 DoubleSummaryStatistics{count=9, sum=4200.000000, min=120.000000, average=466.666667, max=800.000000}
DoubleSummaryStatistics summaryStatistics =list.stream().collect(Collectors.summarizingDouble(Dish::getOalories));
System.out.println(summaryStatistics.toString());///concurrentMap 和 Map使用一样
ConcurrentMap> collect1 =list.stream().collect(Collectors.groupingByConcurrent(Dish::getType));
System.out.println(collect1);///转换为skipListMap
ConcurrentSkipListMap collect2 = list.stream().collect(Collectors.groupingByConcurrent(Dish::getType, ConcurrentSkipListMap::new, Collectors.averagingDouble(Dish::getOalories)));
String collect3= list.stream().collect(Collectors.mapping(Dish::getName, Collectors.joining(",", "[", "]")));
System.out.println(collect3);