集合框架Iterator

Collection a= new ArrayList();//创建Collectiond对象
a.add();//调用方法

Iterator接口迭代器的用法:实现Iterator接口的类会实现三个方法hasNest();next();remove();

public static void main(String[] args){
        Collection c=new Hashset();
         c.add(new Name("f1","l1"));
         c.add(new Name("f2","l2"));
         c.add(new Name("f3","l3"));
                
    Iterator i= c.Iterator();
    while(i.hasnext()){
     Name n=(Name)i.next
     System.out.println(n.getFirstName()+"")
}    

 

posted @ 2017-06-05 17:14  鱼長  阅读(101)  评论(0编辑  收藏  举报