首页 > 其他 > 详细

Iterator

时间:2015-10-22 09:12:33      阅读:297      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!