java8 Stream中groupBy的拓展用法。
取单一字段值、取列表第一个值方式
取某字段成为列表
Map<String, List<String>> ruleMap1 = ruleList.stream(). .collect(Collectors.groupingBy(Rule::getId, Collectors.mapping(Rule::getRuleName, Collectors.toList())));
取列表中第一个值
Map<String, Rule> ruleMap = ruleList.stream(). .collect(Collectors.groupingBy(Rule::getId, Collectors.collectingAndThen(Collectors.toList(), value -> value.get(0))));
来源地址:https://blog.csdn.net/weixin_42260124/article/details/127750156