Collection Iterator 迭代器

使用Collection 中的iterator()方法,调用集合中的迭代方法.

简要说明步骤

Collection coll=new ArrayList();
coll.add("dd");
coll.add("ds");;

Iterator it=coll.iterator(); //定义迭代器
while(it.hasNext()){//判断迭代器是否有元素
System.out.println(it.next());//取出迭代器中的元素
}

 

开发使用下面这种

1 Collection coll=new ArrayList();
2 coll.add("dd");
3 coll.add("ds");
4 
5 for(Iterator it=coll.iterator();it.hasNext();){
6 System.out.println(it.next());
7 }

 

 

posted on 2013-11-24 13:53  ざ柒  阅读(126)  评论(0编辑  收藏  举报