/**
*ArrayList Test
*@author:fly29
*create on 2004-14-18
*/
import Java.util.*;
public class Test
{
public static void main(String[] args)
{
Collection TestSet=new ArrayList();
String name="xingruyi";
int age=22;
Person p=new Person();
//add Person object to ArrayList
for(int i=1;i<5;i++)
{
p.setName(name);
p.setAge(age);
TestSet.add(p);
}
//list the ArrayList
Iterator it=TestSet.iterator();
while(it.hasNext())
{
Person p1=(Person)it.next();
System.out.println("name: "+p1.getName());
System.out.println("age: "+p1.getAge());
}
}
}
//class Person provide Setter and Getter methods
class Person
{
private String name;
private int age;
Person()
{
super();
}
public void setAge(int a)
{
this.age=a;
}
public void setName(String n)
{
this.name=n;
}
public String getName()
{
return this.name;
}
public int getAge()
{
return this.age;
}
}