码迷,mamicode.com
首页 > 其他好文 > 详细

Iterator

时间:2015-10-22 09:13:55      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

(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.

技术分享

Examples:

 1 import java.util.ArrayList;
 2 import java.util.Iterator;
 3 import java.util.List;
 4 
 5 public class ArrayListLoopingExample {
 6     public static void main(String[] args) {
 7 
 8         List<String> list = new ArrayList<String>();
 9         list.add("Text 1");
10         list.add("Text 2");
11         list.add("Text 3");
12 
13         Iterator<String> iterator = list.iterator();
14         while (iterator.hasNext()) {
15             System.out.println(iterator.next());
16         }
17     }
18 }

 

Iterator

标签:

原文地址:http://www.cnblogs.com/ireneyanglan/p/4899757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!