List<User> userList = new ArrayList<>(); userList.sort(Comparator.comparing(User::getEmployeeId)) ;
When the list contains a number of empty elements Science, it will be reported null pointer exception,
Can be used
Comparator.nullsLast(String::compareTo)
Solve the problem element is empty
Results
userList.sort(Comparator.comparing(User::getEmployeeId, Comparator.nullsLast(String::compareTo)));