Iterator it =ts.iterator();
while(it.hasNext())
{
Student stu = (Student)it.next();
System.out.println(stu.getName()+"..."+stu.getAge()
+"..."+stu.getSex()+"..."+"..."+stu.getGrade());
}
}
}
class Student implements Comparable
{
private String name;
private int age;
private String sex;
private int grade;
Student(String name,int age,String sex,int grade)
{
this.name = name;
this.age = age;
this.sex = sex;
this.grade = grade;
}
public int compareTo(Object obj)
{
if(!(obj instanceof Student))
throw new RuntimeException("不是学生类");
Student s = (Student)obj;
if(this.grade>s.grade)
return 1;
if(s.grade==this.grade)
{
return this.name.compareTo(s.name);
}
return -1;
}
//都只提供get()方法,楼主可以自己增加set()方法
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public String getSex()
{
return sex;
}
public int getGrade()
{
return grade;
}