遍历数组、集合的三种方式
int [] array = new int[]{2,3,4,5,6,8}; //普通for循环 for (int i = 0; i < array.length; i++) { System.out.println(array[i]); } //增强for循环 for (int i : array) { System.out.println(i); } //使用迭代器 List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(3); Iterator<Integer> iterator = list.iterator(); while (iterator.hasNext()) { Integer i = iterator.next(); System.out.println(i); }