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