/** * */ package answer; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; /** * @author fuguangming * @version 创建时间:2010-12-10 下午03:02:15 */ public class Doudou { /** * @author fuguangming * @version 创建时间:2010-12-10 下午03:02:15 * @param args */ public static void main(String[] args) { method1(); method2(); } public static void method1(){ Collection l=new ArrayList(); l.add("sadf"); l.add("asdfsdf"); Iterator p = (Iterator) l.iterator(); while (p.hasNext()){ String string=(String)p.next(); System.out.println("------> "+string); } } public static void method2(){ Collection l=new ArrayList(); l.add("sadf"); l.add("asdfsdf"); for(Iterator iterator=l.iterator();iterator.hasNext();){ String string=(String)iterator.next(); System.out.println("------> "+string); } } }