import java.util.*;//一句就够了
public class text
{
public static void main(String[] args)
{
ArrayList l = new ArrayList();
l.add(new Sample("zhangsan",20));
l.add(new Sample("lisi",22));
Iterator it = l.iterator();
while(it.hasNext())
{
Sample sa = (Sample)it.next();
System.out.println(sa.getName()+":"+sa.getAge());
}
}
}
class Sample
{
private String name;
private int age;
Sample(String name,int age)
{
this.name=name;
this.age=age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}
|