stono

http://gwh-08.iteye.com/blog/1233401/

 

class Foo implements Comparable<Foo>{

    

    @Override
    public int compareTo(ClientPortalButton o) {
        return this.i.compareTo(o.getI());
    }

}

 学习了:http://blog.csdn.net/veryisjava/article/details/51675036

可以使用匿名类直接进行排序

public static void main(String[] args) {  
        List<Students> students = new ArrayList<Students>();  
        students.add(new Students(23, 100));  
        students.add(new Students(27, 98));  
        students.add(new Students(29, 99));  
        students.add(new Students(29, 98));  
        students.add(new Students(22, 89));  
        Collections.sort(students, new Comparator<Students>() {  
  
            @Override  
            public int compare(Students o1, Students o2) {  
                int i = o1.getScore() - o2.getScore();  
                if(i == 0){  
                    return o1.getAge() - o2.getAge();  
                }  
                return i;  
            }  
        });  
        for(Students stu : students){  
            System.out.println("score:" + stu.getScore() + ":age" + stu.getAge());  
        }  
}  

 

分类:

技术点:

相关文章:

  • 2021-09-28
  • 2021-09-28
  • 2021-09-28
  • 2021-09-10
  • 2021-05-15
  • 2021-08-18
  • 2022-01-25
  • 2022-12-23
猜你喜欢
  • 2021-09-28
  • 2021-07-19
  • 2022-12-23
  • 2021-10-11
  • 2021-06-07
  • 2021-09-28
  • 2021-09-28
相关资源
相似解决方案