排序
List<User> list = new ArrayList<>(tempList);//tempList中有user對象 list.stream().sorted(Comparator.comparing(User::getSort)).collect(Collectors.toList()); return list; //需要逆序 list.stream().sorted(Comparator.comparing(User::getSort).reversed()).collect(Collectors.toList());
//降序且空值排在最后;nullLast即null值在最后,reverseOrder整個序列降序,最后結果示例 5,4,3,null,null 如果是naturalOrder(),結果示例3,4,5,null,null
//同理,前邊使用nullsFirst,則null值在前邊,后邊控制其他值的降序升序
list.stream().sorted(Comparator.comparing(User::getsort,Comparator.nullsLast(Comparator.reverseOrder()))).collect(Collectors.toList);