Iterator
2015-10-22 08:13
399 查看
(Referrence: TutorialsPoint)
Each of the collection classes provides an iterator( ) method that returns an iterator to the start of the collection. By using this iterator object, you can access each element in the collection, one element at a time.
![](http://images2015.cnblogs.com/blog/788983/201510/788983-20151022081021302-1871547992.png)
Examples:
Each of the collection classes provides an iterator( ) method that returns an iterator to the start of the collection. By using this iterator object, you can access each element in the collection, one element at a time.
![](http://images2015.cnblogs.com/blog/788983/201510/788983-20151022081021302-1871547992.png)
Examples:
import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class ArrayListLoopingExample { public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("Text 1"); list.add("Text 2"); list.add("Text 3"); Iterator<String> iterator = list.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } }
相关文章推荐
- IE input file隐藏不能上传文件解决方法
- 如何从上位机或者触摸屏设定Time或S5Time值?
- OC多个形参
- OC学习笔记之Block基础知识
- Online random forest
- 【基础练习】【DFS】codevs2549 自然数和分解题解
- 【基础练习】【DFS】codevs2806 红与黑题解
- SQL Server中的事务日志管理(4/9):简单恢复模式里的日志管理
- 每天一个linux命令(17):whereis 命令
- OC学习笔记之NSMutableDictionary
- 在 Linux 下使用 RAID(八):当软件 RAID 故障时如何恢复和重建数据
- 在 Linux 下使用 RAID(八):当软件 RAID 故障时如何恢复和重建数据
- 【笨木头Unity】入门之旅003:HelloWorld
- 【笨木头Unity】入门之旅002:不谈对象,咱们谈组件
- 【日常学习】【搜索递推和其他】10.21.2015校内测试总结
- JavaScript的作用域
- Leetcode 81. Search in Rotated Sorted Array II
- Java中生成的UUID(全局唯一标识符-----(唯一)-------)
- 使用python对url编码解码
- Leetcode 33. Search in Rotated Sorted Array