import java.util.Iterator;
import java.util.TreeSet;
public class TreeSet {
public static void main(String[] args) {
TreeSet<Student> ts = new TreeSet<Student>();
Student s1 = new Student("李白", 28);
Student s2 = new Student("杜甫", 25);
Student s3 = new Student("李白", 28);
Student s4 = new Student("白居易", 23);
Student s5 = new Student("杜甫", 25);
Student s6 = new Student("李清照", 25);
Student s7 = new Student("李照", 35);
Student s8 = new Student("李", 27);
ts.add(s1);
ts.add(s2);
ts.add(s3);
ts.add(s4);
ts.add(s5);
ts.add(s6);
ts.add(s7);
ts.add(s8);
Iterator<Student> it = ts.iterator();
while (it.hasNext()) {
Students s = it.next();
System.out.println(s.getName() + "***" + s.getAge());
}
}
}
|
|