I need to get unique key and that key related object variable in HashMap
.
I have a list of items
public class Java8Examples3 {
public static void main(String[] args) {
// 3 apple, 2 banana, others 1
List<Item> items = Arrays.asList(new Item("KPIT", 10, new BigDecimal("9.99")),
new Item("CTS", 20, new BigDecimal("19.99")), new Item("WIPRO", 10, new BigDecimal("29.99")),
new Item("INFOSYS", 10, new BigDecimal("29.99")), new Item("ESTUATE", 20, new BigDecimal("9.99")),
new Item("KPIT", 10, new BigDecimal("9.999")), new Item("CTS", 10, new BigDecimal("19.99")),
new Item("KPIT", 20, new BigDecimal("9.999")));
Map<String, List<Item>> counting = items.stream()
.collect(Collectors.groupingBy(Item::getName, Collectors.toList()));
}
}
My Output will look like this:
KPIT: 10,10,20
CTS:20,10
WIPRO:10
INFOSYS:10
TCS:20