import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class ylq {
public static void main(String[] args) {
Set<Student> set=new TreeSet<Student>();
set.add(new Student(23,"ylq"));
set.add(new Student(22,"zzy"));
set.add(new Student(23,"yyb"));
Iterator<Student> it=set.iterator();
while(it.hasNext())
{
Student s=it.next();
System.out.println(s.getage()+s.getname());
}
}
}
public class Student implements Comparable{
private int age;
private String name;
Student(int age,String name)
{
this.age=age;
this.name=name;
}
public int compareTo(Object o) {
Student stu=(Student) o;
if(this.age>stu.age)
return 1;
if(this.age==stu.age)
return this.name.compareTo(stu.name);
return -1;
}
public int getage()
{
return age;
}
public String getname()
{
return name;
}
}
|
|