zoukankan      html  css  js  c++  java
  • Collections.sort的两种用法

    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());  
            }  
    }  
  • 相关阅读:
    Go反射原理
    并发控制--context篇
    Go并发控制--WaitGroup篇
    Go依赖管理--module
    正睿培训 8.4 学习笔记
    bitset
    7.18 学习笔记
    7.17 学习笔记
    P6835 [Cnoi2020]线形生物
    UVA11300 Spreading the Wealth 思维题
  • 原文地址:https://www.cnblogs.com/stono/p/4759394.html
Copyright © 2011-2022 走看看