Java迭代器——更灵活的遍历方式

Java中所有的Collection都可以使用foreach语法遍历

 1 import java.util.*;
 2 
 3 public class SimpleCollection {
 4     public static void main(String[] args) {
 5         Collection<Integer> c = new ArrayList<Integer>();
 6 
 7          for(int i = 0; i < 10; i++)
 8             c.add(i);
 9          for(Interger i : c)
10             System.out.print(i + ",");
11     }
12 }
13 
14 //output:0,1,2,3,4,5,6,7,8,9

 


 

迭代器

 

 

posted @ 2018-07-11 21:15  hoanfir  阅读(261)  评论(0编辑  收藏  举报