标签:style static ack iterator span author public tree new
1 package com.ietree.basic.collection.loop; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 import java.util.List; 6 7 /** 8 * List遍历 9 * 10 * @author Dylan 11 */ 12 public class ListLoop { 13 14 public static void main(String[] args) { 15 16 // 初始化一个长度为10的ArrayList 17 List<Integer> list = new ArrayList<Integer>(); 18 for (int i = 0; i < 10; i++) { 19 list.add(i); 20 } 21 22 // 循环List的几种方法: 23 // 方式一: 24 Iterator it1 = list.iterator(); 25 while (it1.hasNext()) { 26 System.out.println(it1.next()); 27 } 28 29 // 方式二: 30 for (Iterator it2 = list.iterator(); it2.hasNext();) { 31 System.out.println(it2.next()); 32 } 33 34 // 方式三: 35 for (Integer temp : list) { 36 System.out.println(temp); 37 } 38 39 // 方式四: 40 for (int i = 0; i < list.size(); i++) { 41 System.out.println(list.get(i)); 42 } 43 } 44 45 }
标签:style static ack iterator span author public tree new
原文地址:http://www.cnblogs.com/Dylansuns/p/6759751.html