package ArrayListDemo;
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayListDemo1 {
public static void main(String[] args) {
ArrayList array=new ArrayList();
array.add("hello");
array.add("world");
array.add("java");
Iterator it=array.iterator();
while(it.hasNext()) {
String s=(String)it.next();
System.out.println(s);
}
for(int x=0;x<array.size();x++) {
String s=(String)array.get(x);
System.out.println(s);
}
}
}
package ArrayListDemo;
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayListDemo2_student {
public static void main(String[] args) {
ArrayList array=new ArrayList();
Student s1=new Student("白敬亭",22);
Student s2=new Student("goodbai",23);
Student s3=new Student("ruilin",25);
Student s4=new Student("yundi",39);
array.add(s1);
array.add(s2);
array.add(s3);
array.add(s4);
Iterator it=array.iterator();
while(it.hasNext()) {
Student s=(Student)it.next();
System.out.println(s.getName()+"---"+s.getAge());
}
for(int x=0;x<array.size();x++) {
Student s=(Student)it.next();
System.out.println(s.getName()+"---"+s.getAge());
}
}
}