I have data like this:
[
{
"category":"Fruits",
"name":"Apple"
},
{
"category":"Fruits",
"name":"Manggo"
},
{
"category":"Vegetables",
"name":"Water Spinach"
}
]
I want to grouping by java 8, I've tried with :
Map<String, List<MyData>> myData
= list.stream().collect(Collectors.groupingBy(d -> d.getCategory()));
But the result is not what I need. Because the result I expected was Fruits = 2, Vegetables = 1