1、list转map
参考:https://blog.csdn.net/qq_39629277/article/details/83012548
//按对象中的两个字段生成Map
list.stream().collect(Collectors.toMap(SysConfigDO::getParamKey, SysConfigDO::getParamValue))
//按对象中的字段和对象本身生成Map
list.stream().collect(Collectors.toMap(SysConfigDO::getParamKey, p -> p));
//按对象中字段封装后做Key,并返回Map分组
Map<String, List<BdOutSubOrderEntity>> collect1 = subList.stream().collect(Collectors.groupingBy(item -> item.getOuterOrderId().intValue() + ""));
//按对象中字段封装后做Key,并返回Map
Map<String, BdOutSubOrderEntity> collect2 = subList.stream().collect(Collectors.toMap(item -> item.getOuterOrderId().intValue() + "", p -> p));
网友评论