import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Iterator;
import java.util.List;
/**
* 遍历数组四种方法
*
* @author JRunner
*
* 2009-10-26
*
* Email: JRunner@126.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);
}
}
* 遍历数组四种方法
*
* @author JRunner
*
* 2009-10-26
*
* Email: JRunner@126.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);
}
}
}