OiO.lk Blog java Grouping by and map value
java

Grouping by and map value


I have the following data

[
 {name:a,roll:2,id:3,age:24,city:goa},  
 {name:b,roll:3,id:3,age:24,city:Delhi},  
 {name:c,roll:2,id:1,age:27,city:goa}
]

What I want is

{
   2: [a,c]
   3: [b]
}

I have done the below :

objectList.stream().collect(Collectors.groupingBy(ObjectRecord::roll))

But this is giving back the list of the fill object:

{
   2: [{name:a,roll:2,id:3,age:24,city:goa},{name:c,roll:2,id:1,age:27,city:goa}]
   3: [{name:b,roll:3,id:3,age:24,city:Delhi}]
}



You need to sign in to view this answers

Exit mobile version