1.list 过滤 --得到和map匹配的list
List<CustInfo> custInfoList = tmpList.stream().filter(t -> map.containsKey(t.CustNo)).collect(Collectors.toList());
2.分组求和 --根据custNo和sellCodeNo 分组,对money求和 得到一个map
Map<String,Double> tmpMap = new HashMap<>();
tmpMap = orderList.stream().collect(Collectors.groupingBy(
t -> t.custNo + '-' + t.sellCodeNo , Collectors.summingDouble(t -> t.money)));
3.提取List中一个或多个字段并去重
List<String> orderList = tmpList.stream().map(t -> t.custNo + '-' + t.orderSno).distinct().collect(Collectors.toList());
4.对List多个字段分组
Map<String, List<Order>> orderMap = tmpList.stream.collect(Collectors.groupingBy(
t -> t.custNo + '-' + t.sellCodeNo)
5.List转Map
Map<String,User> maps = custInfoList.stream.collect(Collectors.toMap(User::getId,user -> user));
Map<String,User> maps = custInfoList.stream.collect(Collectors.toMap(User::getId,Function.identity(),(key1,key2) -> key2));
//key重复需要指定第三个参数
6.根据多个字段分组,取每组最大
Map<String,User> Map = List.stream().collect(
Collectors.groupingBy(t -> t.custid + '-' + t.name,
Collectors.collectingAndThen(
Collectors.reducing((nav1,nav2) -> 2>1 ? 2 : 1), Optional::get
)
)
);