Collection中的迭代器

迭代器:boolean hasNext() 判断集合中是否还有没有被取出数据
nexe() 取出集合中下一个元素
package
cn.lijun.demo4; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class CollectionDemo1 { public static void main(String[] args) { //集合中可以存储任意类型 Collection coll=new ArrayList<>(); coll.add("a"); coll.add("sadsadsa"); //迭代器 获取迭代器 Iterator it=coll.iterator(); while(it.hasNext()){ String s=(String)it.next(); System.out.println(s); System.out.println(s.length()); } } }

 

posted @ 2019-03-21 12:13  芯-觞  阅读(431)  评论(0编辑  收藏  举报