import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Iterator;
import java.util.List;
/**
* 遍历数组四种方法
*/
class Test {
/**
* 注:Iterator 迭代器
*/
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);
}
}
* 遍历数组四种方法
*/
class Test {
/**
* 注:Iterator 迭代器
*/
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);
}
}
}
本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/articles/2489423.html,如需转载请自行联系原作者