码迷,mamicode.com
首页 > 编程语言 > 详细

thinking java

时间:2015-10-03 10:40:58      阅读:214      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!