Board logo

标题: 遍历数组四种方法 [打印本页]

作者: qingqing3721    时间: 2011-8-17 20:22     标题: 遍历数组四种方法

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




欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/) Powered by Discuz! 6.0.0