Map>> maplist = dclist.stream()
.collect(Collectors.groupingBy(map -> map.get("name"),
Collectors.mapping(map -> {
Map temp = new HashMap(map);
temp.remove("name");
return temp;
}, Collectors.toList())));
List> res = new ArrayList<>();
for (String key : maplist.keySet()) {
res.add(Map.of("name", key, "dclist", maplist.get(key)));
}
原格式
[
{
"dc": 0.100,
"date": "202003-1",
"name": "测试1"
},
{
"dc": 0.100,
"name": "测试1",
"date": "202003-2"
},
{
"dc": 0.100,
"name": "测试1",
"date": "202003-4"
},</