让元素所属的类实现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