List排序
方法一:实现接口
public class Task implements Comparable<Task>{ @Override public int compareTo(Task other) { return this.status - other.getStatus(); } } List<Task> workcenters = ……; Collections.sort(workcenters);
方法二:匿名方法
Collections.sort(members, new Comparator<ProjectMember>() { public int compare(ProjectMember arg0, ProjectMember arg1) { return arg0.getEmployeeId().compareTo(arg1.getEmployeeId()); } });
方法三:jdk8
List<String> sortedNames = names.stream().sorted().collect(Collectors.toList());
签名:删除冗余的代码最开心,找不到删除的代码最痛苦!