使用ArrayList来存放这些元素。例如有一个类People,可以采用如下方式来存放该类的一系列对象。People p1 = new People(); //先实例化3个对象
People p2 = new People();
People p3 = new People();
ArrayList<People> peoples = new ArrayList<People>();//实例化一个ArrayList
people.add(p1);//使用add方法往ArrayList中添加元素p1
people.add(p2);//往ArrayList中添加元素p2
people.add(p3);//往ArrayList中添加元素p3
people.get(0); //使用get方法从ArrayList中取出元素盘p1
people.get(1);
people.get(2);