import java.util.ArrayList;
import java.util.Iterator;
import java.util.TreeSet;
public class test1 {
public static void main(String[] args) {
//创建对象,加泛型
TreeSet t1 = new TreeSet();
Person p1=new Person("lisi1",23);
Person p2=new Person("lisi3",22);
Person p3=new Person("lisi4",25);
Person p4=new Person("lisi6",26);
//添加元素
t1.add(p4);
t1.add(p3);
t1.add(p2);
t1.add(p1);
//增强for与下面Iterator输出一个意思
/*for (Person person : t1) {
System.out.println(person);
}*/
Iterator it = t1.iterator();
while(it.hasNext()){
Person p11 = (Person)it.next();
System.out.println(p11.getName()+"*******"+p11.getAge());
}
}
}
|