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());

  

posted @ 2017-11-28 13:27  Season2009  阅读(128)  评论(0编辑  收藏  举报