收集Java8 Lambda map-reduce代码

 

一段代码-累计

        Map<String, Long> idCountMap2 = new HashMap<>();
        idCountMap2.put("1", 10L);
        idCountMap2.put("2", 12L);

        entries.addAll(idCountMap.entrySet());
        entries.addAll(idCountMap2.entrySet());

        Map<String, Long> total = entries.stream()
                .collect(Collectors.groupingBy(m -> m.getKey(), Collectors.summingLong(m -> m.getValue())));

 

posted @ 2022-01-24 12:44  multitude  阅读(117)  评论(0编辑  收藏  举报