//创建学生类的对象,作为TreeSet的元素
public class Student {
private String name;
private int score;
public Student(String name,int score){
this.name=name;
this.score=score;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public int getScore(){
return score;
}
public void setScore(int score){
this.score=score;
}
}
//本类作为比较器,指定比较方法
import java.util.*;
public class ComparaScore implements Comparator<Student>{
public int compare(Student stu1,Student stu2){
if(stu1.getScore()<stu2.getScore())
return 1;
if(stu1.getScore()>stu2.getScore())
return -1;
return 0;
}
public boolean equals(Object obj){
return super.equals(obj);