1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| List<Map<String, String>> data = ListUtil.toList( MapUtil.builder("name", "sam").put("count", "80").map(), MapUtil.builder("name", "sam").put("count", "81").map(), MapUtil.builder("name", "sam").put("count", "82").map(), MapUtil.builder("name", "jack").put("count", "80").map(), MapUtil.builder("name", "jack").put("count", "90").map() );
Map<String, Map<String, List<String>>> nameMap = data.stream() .collect(Collectors.groupingBy(e -> e.get("name"), CollectorUtil.reduceListMap())); Assert.assertEquals(MapUtil.builder("jack", MapUtil.builder("name", Arrays.asList("jack", "jack")) .put("count", Arrays.asList("80", "90")).build()) .put("sam", MapUtil.builder("name", Arrays.asList("sam", "sam", "sam")) .put("count", Arrays.asList("80", "81", "82")).build()) .build(), nameMap);
|