List<User> userList = new ArrayList<>(); userList.sort(Comparator.comparing(User::getEmployeeId)) ;
当列表中含有学号为空的元素时,会报空指针异常,
可采用
Comparator.nullsLast(String::compareTo)
解决元素的值为空的问题
结果为
userList.sort(Comparator.comparing(User::getEmployeeId, Comparator.nullsLast(String::compareTo)));