int类型
List<Integer> list= new ArrayList<>();
list.add(3);
list.add(5);
list.add(1);
List<Integer> collect = list.stream()
.sorted(Comparator.comparingInt(Integer::intValue))
.collect(Collectors.toList());
System.out.println(collect);
List<Integer> collect = list.stream()
.sorted(Comparator.comparingInt(Integer::intValue).reversed())
.collect(Collectors.toList());
String类型
List<String> list= new ArrayList<>();
list.add("a");
list.add("c");
list.add("b");
List<String> collect = list.stream()
.sorted(Comparator.comparing(String::toString))
.collect(Collectors.toList());
System.out.println(collect);
List<String> list= new ArrayList<>();
list.add("a1");
list.add("c11");
list.add("b111");
List<String> collect = list.stream()
.sorted(Comparator.comparing(String::length))
.collect(Collectors.toList());
System.out.println(collect);
Long类型
List<Long> list= new ArrayList<>();
list.add(3L);
list.add(5L);
list.add(1L);
List<Long> collect = list.stream()
.sorted(Comparator.comparingLong(Long::longValue))
.collect(Collectors.toList());
System.out.println(collect);
对象类型
List<OutStoreDetail> sortDetailList = outStoreDetails.stream()
.sorted(Comparator.comparing(OutStoreDetail::getProductType))
.collect(Collectors.toList());
Map类型
List<Map<String,Object>> list= new ArrayList<>();
Map<String, Object> m1 = new HashMap<>();
m1.put("id", 1);
m1.put("name", "刘一");
m1.put("age", 28);
m1.put("height", new BigDecimal("1.92"));
Map<String, Object> m2 = new HashMap<>();
m2.put("id", 2);
m2.put("name", "陈二");
m2.put("age", 18);
m2.put("height", new BigDecimal("1.90"));
list.add(m1);
list.add(m2);
List<Map<String, Object>> collect = list.stream()
.sorted(Comparator.comparing(item -> Integer.parseInt(item.get("age").toString())))
.collect(Collectors.toList());
System.out.println(collect);