/**
*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;
}
}
闽公网安备 35060202000074号