public class ArrayListDemo2 {
public static void main(String[] args) {
ArrayList array = new ArrayList();
Student s1 = new Student("乔峰", 40);
Student s2 = new Student("虚竹", 36);
Student s3 = new Student("段誉", 28);
array.add(s1);
array.add(s2);
array.add(s3);
Iterator it = array.iterator();
while (it.hasNext()) {
Student s = (Student) it.next();
System.out.println(s.getName() + "***" + s.getAge());
}
System.out.println("-------------");
for (int x = 0; x < array.size(); x++) {
Student s = (Student) array.get(x);
System.out.println(s.getName() + "***" + s.getAge());
}
}
}
|
|