I have a class
public class ProductStock {
private Long id;
private Integer quantity;
}
and a list like
List<ProductStock> productStocks =
{
ProductStock(1, 1),
ProductStock(2, 1),
ProductStock(3, 1),
ProductStock(1, 1),
ProductStock(4, 1),
ProductStock(5, 1),
ProductStock(2, 1)
}
I want to group productStocks by id. What is the best way to convert this list like bellow
productStocks =
{
ProductStock(1, 2),
ProductStock(2, 2),
ProductStock(3, 1),
ProductStock(4, 1),
ProductStock(5, 1)
}