List list=new ArrayList();
Person p1=new Person("lisi1",21);
Person p2=new Person("lisi1",21);
list.add(p1);
list.add(p2);
list.add("lisi3",23);
for(Iterator it=list.iterator();it.hasNext();){
//向下转型
if(it.next() instanceof Person){
Person p=(Person)it.next();
}
System.out.println(p.getName()":"p.getAge());
}
public class Person {
private String name;
private int age;
public Person(){
super();
}
//get set方法省略
}