首页 > 其他分享 >Compareble自然排序器

Compareble自然排序器

时间:2022-12-18 10:34:14浏览次数:33  
标签:int 自然 Object Compareble current score 排序

让元素所属的类实现Comparable接口,重写compareTo(Object o)方法
Collections调用sort方法 即可按照规则排序

  public int compareTo(Object o) {
        Student current=(Student)o;
        //按照成绩升序score-current.score,降序current.score-score
        return (int)(score-current.score);
    }

标签:int,自然,Object,Compareble,current,score,排序
From: https://www.cnblogs.com/Sco-/p/16990056.html

相关文章