1 import java.util.ArrayList; 2 import java.util.Iterator; 3 import java.util.List; 4 public class Bianli { 5 public static void main(String[] args) { 6 List<String> list = new ArrayList<String>(); 7 list.add("add"); 8 list.add("bdd"); 9 list.add("cdd"); 10 // 三种遍历方式 for();for()增强;iterator 11 for (int i = 0; i < list.size(); i++) { 12 String s = list.get(i); 13 System.out.println(s); 14 } 15 for (String string : list) { 16 System.out.println(string); 17 } 18 Iterator<String> iterator = list.iterator(); 19 while(iterator.hasNext()){ 20 System.out.println(iterator.next()); 21 } 22 } 23 }
时间: 2024-10-11 01:30:50