我有一个地图列表,我想按名称对其进行分组
List<Map> allObjs = new ArrayList<Map>();
Map<String, Object> src = new HashMap();
src.put("name", "asset1");
src.put("description", "desc1" );
src.put("definition", "def1" );
Map<String, Object> src2 = new HashMap();
src2.put("name", "asset1");
src2.put("description", "desc2" );
src2.put("definition", "def2" );
allObjs.add(src);
allObjs.add(src2);
我尝试将它们分组
Map<Object, List<Map>> result = allObjs.stream().collect(Collectors.groupingBy(p -> p.get("name")));
我想要的是
{
name=asset1,
description=["desc1","desc2"],
definition=["def1","def2"]
}
我希望将所有其他键分组在一个列表中但我得到的是
{asset1=[
{name=asset1, description=desc1, definition=def2},
{name=asset1, description=desc2, definition=def2}
]
}
我如何将除名称之外的所有其他键分组到上面预期的列表中?