首页 > 编程语言 > 详细

thinking java

时间:2015-10-03 10:38:59      阅读:183      评论:0      收藏:0      [点我收藏+]
public class CrossContainerIteration{
    public static void display(Iterator<Pet> it){
            while(it.hasNext()){
                    Pet tmp = it.next();
                    System.out.print("输出:"+tmp.id());
                }
        }
    public static void main(String[] args){
            ArrayList<Pet> pets = Pets.arrayList(8);
            LinkedList<Pet> petsLL = new LinkedList<Pet>(pets);
            HashSet<Pet> petsHS = new HashSet<Pet>(pets);
            TreeSet<Pet> petsTS = new TreeSet<Pet>(pets);
            display(pets.iterator());
            display(petsLL.iterator());
            display(petsHS.iterator());
            display(petsTS.iterator());
        }
    }

1. Iterator的作用:能够将遍历序列的 操作与存储序列的容器结构分离。由此,可以说迭代器统一了对容器的访问方式。

thinking java

原文:http://www.cnblogs.com/androiddream/p/4853089.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!