groovy中
import java.util.stream.Collectors
List params = []
Map temp = [:]
temp.put("id",1)
temp.put("name","qq")
temp.put("height","180")
params.add(temp)
temp = new HashMap()
temp.put("id",1)
temp.put("name","www")
temp.put("height","111")
params.add(temp)
temp = new HashMap()
temp.put("id",2)
temp.put("name","eee")
temp.put("height","222")
params.add(temp)
Map<Integer, List<Map>> groupBy = params.stream().collect(Collectors.groupingBy({it.id}))
System.out.println(groupBy)
排序后的结果是一个Map,它的key是分组的组号,value是List,List中是分组后的Map
java中
List<Map<String,Object>> params = new ArrayList<>();
Map<String,Object> temp = new HashMap<>();
temp.put("id",1);
temp.put("name","qq");
temp.put("height","180");
params.add(temp);
temp = new HashMap<>();
temp.put("id",1);
temp.put("name","www");
temp.put("height","111");
params.add(temp);
temp = new HashMap<>();
temp.put("id",2);
temp.put("name","eee");
temp.put("height","222");
params.add(temp);
Map groupBy = params.stream().collect(Collectors.groupingBy(it->it.get("id")));
System.out.println(groupBy);