集合遍歷方法
//集合的遍歷
Collection c=new ArrayList();
c.add("hello");
c.add("world");
c.add("java");
//第一種方法:把集合轉換成數組
Object[] objs=c.toArray();
for (int i = 0; i < objs.length; i++) {
System.out.println(objs[i]);
String s=(String) objs[i];
System.out.println("s的長度:"+s.length());
}
//第二種方法:使用迭代器遍歷方式
Iterator it=c.iterator();
while(it.hasNext()){
String s=(String)it.next();
System.out.println(s);
} //第三種方法,for增強
for(Object object:c ){
System.out.println(object);
}