import java.util.*;
//import java.util.Comparator;
//import java.util.Iterator;
//import java.util.TreeSet;
public class test9 {
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
TreeSet set =new TreeSet(new bijiaoqi());
set.add(new student("s",12,85));
set.add(new student("d",10,75));
set.add(new student("w",14,74));
set.add(new student("s",10,70));
set.add(new student("r",14,71));
Iterator it = set.iterator();
while(it.hasNext())
{
student stu =(student) it.next();
System.out.println("姓名:"+stu.getName()+"年龄:"+stu.getAge()+"分数:"+stu.getFenshu());
}
}
}
class student
{
private String name ;
private int age;
private int fenshu;
student (String name,int age,int fenshu)
{
this.name=name;
this.age=age;
this.fenshu=fenshu;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getFenshu() {
return fenshu;
}
public void setFenshu(int fenshu) {
this.fenshu = fenshu;
}
}
class bijiaoqi implements Comparator
{
public int compare(Object o1,Object o2)
{
student a1=(student)o1;
student a2=(student)o2;
return a1.getFenshu()-a2.getFenshu();
}
} |