1 package com.zuoye; 2 3 import java.util.*; 4 5 public class jihe { 6 7 public static void main(String[] args) { 8 9 List<Object> a=new ArrayList<Object>(); 10 11 for(int i=1;i<=100;i++) 12 { 13 a.add(i); 14 } 15 16 System.out.println("遍历方式一"); 17 for(Object t: a) 18 { 19 System.out.print(" "+t); 20 } 21 System.out.println(""); 22 23 System.out.println("遍历方式二"); 24 25 for(int j=0;j<a.size();j++) 26 { 27 System.out.print(" " +a.get(j)); 28 } 29 System.out.println(""); 30 31 System.out.println("遍历方式三:迭代器"); 32 33 Iterator<Object> it=a.iterator(); 34 35 while(it.hasNext()) 36 { 37 Object t=it.next(); 38 39 System.out.print(" " +t); 40 } 41 42 System.out.println(""); 43 44 System.out.println("移除索引位置为10的对象的结果:"); 45 46 //移除索引位置为10的对象 47 48 a.remove(10); 49 50 for(Object t: a) 51 { 52 System.out.print(" "+t); 53 } 54 } 55 56 }
最后结果为: