标签:list arraylist tor for循环 bsp style res string 迭代器
List<String> list1 = new ArrayList<String>(); list1.add("1"); list1.add("2"); list1.add("3"); list1.add("4"); // 1、普通话for循环 String res = ""; for (int i = 0; i < list1.size(); i++) { res += list1.get(i); } System.out.println(res); // 2、增强for String res2 = ""; for (String item : list1) { res2 += item; } System.out.println(res2); // 3、使用迭代器遍历 Iterator<String> it = list1.iterator(); String res3 = ""; while (it.hasNext()) { res3 += it.next(); } System.out.println(res3);
标签:list arraylist tor for循环 bsp style res string 迭代器
原文地址:http://www.cnblogs.com/wms01/p/7532477.html