public class People
{
private int age;
public People()
{
age=0;
}
public void setAge(int nn)
{
age=nn;
}
public int getAge()
{
return age;
}
}
------------------------------------------------------
import java.util.Vector;
import javax.swing.*;
public class TestPeople
{
People vv, tt;
Vector pep;
String out=" ";
public TestPeople()
{
int a,b,c;
pep=new Vector(10);
for(a=0;a<pep.capacity();a++)
{
pep.add(a, new People()); // create 10 People objects and put ref
in vector
}
// fill all objects with dummy ages 10 thru 100
// all references to pep in the code below could be preceeded by "this"
// if multiple vextors existed (??) like an array of TestPeople
for( b=10,c=0;b<=100;b+=10,c++)
{
tt=(People)pep.remove(c); // notice the casting
tt.setAge(b);
pep.add(c,tt);
}
// pull them out backwards and concatenate to print
for(c=9;c>=0;c--)
{
tt=(People)pep.remove(c);
out+=tt.getAge()+" ";
}
JOptionPane.showMessageDialog(null,out);
}
public static void main(String[] args)
{
new TestPeople();
}
}