thinking java
2015-10-03 10:07
525 查看
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的作用:能够将遍历序列的 操作与存储序列的容器结构分离。由此,可以说迭代器统一了对容器的访问方式。
相关文章推荐
- eclipse插件开发 plugin.xml extensions下右键 没有提示
- Spring MVC请求过程
- Servlet 要点总结
- 进程列表中多个JAVA进程的区分识别
- Java设置环境变量
- 本地mapReduce项目报错:java.io.IOException: Unable to establish loopback connection;
- Ubuntu装JDK
- eclipse修改web项目部署路径
- java中方法重载和重写的区别和定义
- Spring Boot Tutorials
- 动态代理(jdk)+cglib技术
- java -version javac -version 版本不一致
- java中的正则表达式捕获组与引用的概念
- 关于TreeSet<E>泛型类中的compareTo()方法的调用
- Java泛型详解
- Java容器集合类的区别用法
- java xml 格式化输出
- 编译eclipse hadoop插件
- Eclipse 中设置JVM 内存
- 类和对象浅谈(3)