import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* 遍历集合、数组的四种方法
*
* @author JRunner
*
* Email:jrunner@sina.com
*/
class Test {
/**
*
* 注:Iterator 迭代器
*
* @param args
*/
public static void main(String[] args) {
Test1 t = new Test1();
Test1 t1 = new Test1();
List list = new ArrayList();
list.add(1);
list.add(2);
list.add(4);
list.add(3);
Iterator iterator = list.iterator();
System.out.println("------方法一-------");
while (iterator.hasNext()) {
int i = Integer.parseInt(iterator.next().toString());
System.out.println(i);
}
System.out.println("------方法二-------");
for (Iterator iter = list.iterator(); iter.hasNext();) {
int i = Integer.parseInt(iter.next().toString());
System.out.println(i);
}
System.out.println("------方法三-------");
for (Object obj : list) {
System.out.println(obj);
}
System.out.println("------方法四-------");
for (int i = 0; i < list.size(); i++) {
int k = Integer.parseInt(list.get(i).toString());
System.out.println(k);
}
}
}