I have List that looks like this:
List
[{
type: "1"
price: 10.0
count: 2
},
type: "1"
price: 15.0
count: 3
},
type: "2"
price: 20.0
count: 2
},
type: "2"
price: 30.0
count: 3
}]
I need to group this such that I only have two types (in this case).
Output:
[{
type: "1"
price: 25.0
count: 5
},
type: "2"
price: 50.0
count: 5
}]
So, basically, the number of elements in the list will be equal to the number of unique types. And other values like price and count will be summed.
I tried using this -
report.stream().collect(Collectors.groupingBy(x -> x.getStuffe));
But, this gives a Map. I don't need a Map, I need a List.
How can I do this?