1 package com.test; 2 import java.util.ArrayList; 3 import java.util.Iterator; 4 import java.util.List; 5 public class ArrayListDemo { 6 public static void main(String args[]){ 7 List<String> list = new ArrayList<String>(); 8 list.add("luojiahui"); 9 list.add("luojiafeng"); 10 //方法1 11 Iterator it1 = list.iterator(); 12 while(it1.hasNext()){ 13 System.out.println(it1.next()); 14 } 15 //方法2 16 for(Iterator it2 = list.iterator();it2.hasNext();){ 17 System.out.println(it2.next()); 18 } 19 //方法3 20 for(String tmp:list){ 21 System.out.println(tmp); 22 } 23 //方法4 24 for(int i = 0;i < list.size(); i ++){ 25 System.out.println(list.get(i)); 26 } 27 } 28 }