sort 排序
public static void main(String[] args) {
List<Inventory> inventoryList = new ArrayList<>();
Inventory inventory = new Inventory();
inventory.setWeight(new BigDecimal("2.1"));
Inventory inventory1 = new Inventory();
inventory1.setWeight(new BigDecimal("1.1"));
inventoryList.add(inventory);
inventoryList.add(inventory1);
// 1. comparing 升序
inventoryList.sort(Comparator.comparing(Inventory::getWeight));
System.out.println(JSON.toJSONString(inventoryList));
// 2. 降序
inventoryList = inventoryList.stream().sorted(Comparator.comparing(Inventory::getWeight).reversed()).collect(Collectors.toList());
System.out.println(JSON.toJSONString(inventoryList));
// 3. 按照数量升序,重量降序
inventoryList = inventoryList.stream().sorted(Comparator.comparing(Inventory::getNum).thenComparing(Comparator.comparing(Inventory::getWeight).reversed())).collect(Collectors.toList());
System.out.println(JSON.toJSONString(inventoryList));
}