package cn.bean;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class ListTestPerson {
/**
* @param args
*/
public static void main(String[] args) {
List list = new ArrayList();
Person p1 = new Person("11",11);
Person p2 = new Person("22",22);
list.add(p1);
list.add(p2);
method1(list);
method2(list);
method3(list);
method4(list);
//}
//private static void method2() {
//}
}
private static void method4(List list) {
for(int i = 0;i< list.size();i++){
Person p = (Person)list.get(i);
System.out.println(p);
}
}
private static void method3(List list) {
ListIterator li = list.listIterator();
while (li.hasNext()){
Person p = (Person) li.next();
System.out.println(p);
}
}
private static void method2(List list) {
Iterator it = list.iterator();
while (it.hasNext()){
Person p = (Person)it.next();
System.out.println(p);
}
}
private static void method1(List list) {
Object[] objs = list.toArray();
for (int i = 0;i < objs.length;i++){
Person p = (Person)objs[i];
System.out.println(p);
}
}
} |
|