I am trying to sort items by the price, but each item belongs to a category so I have to create a map with categories as key and items as value and I have to sort it using Comparator
class.
This is Comparator
class
public class ProductionSorter implements Comparator<Item> {
public ProductionSorter(){};
@Override
public int compare (Item a, Item b){
return a.getSellingPrice().compareTo(b.getSellingPrice());
}
}
This is the map
Map <Category, List<Item>> mapOfItems = items
.stream()
.collect(Collectors.groupingBy(Item::getCategory));
I am not sure how to sort items by price on this map.