1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
// 分组统计 Map<String, Long> countMap = records.stream().collect(Collectors.groupingBy(o -> o.getProductType() + "_" + o.getCountry(), Collectors.counting())); List<Record> countRecords = countMap.keySet().stream().map(key -> { String[] temp = key.split( "_" ); String productType = temp[ 0 ]; String country = temp[ 1 ]; Record record = new Record(); record.set( "device_type" , productType); record.set( "location" , country; record.set( "count" , countMap.get(key).intValue()); return record; }).collect(Collectors.toList()); |
作者:尤灯塔
出处:https://www.cnblogs.com/30go/