I have a list of map for which i want to group them by name
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);
I tried grouping them by
Map<Object, List<Map>> result = allObjs.stream().collect(Collectors.groupingBy(p -> p.get("name")));
What i want is
{
name=asset1,
description=["desc1","desc2"],
definition=["def1","def2"]
}
I want all the other keys to be grouped in a list But what i got is
{asset1=[
{name=asset1, description=desc1, definition=def2},
{name=asset1, description=desc2, definition=def2}
]
}
How do i group all the other keys except name to a list like expected above?