Java——JDK1.5新增强的for循环

<1>JDK1.5新增的for循环对于遍历array或collection非常便利。

<2>缺陷:
       数组:不能方便地访问下标值。
       集合:与使用Interator相比,不能方便地删除集合中的东西。
                 在内部也是调用Interato
<3>总结:
       除了简单遍历并读出其中的内容,不建议使用增强for。
 
【程序分析】
  
  int[] arr = {1,2,3,4,5};
  for(int i : arr){
            System.out.println(i);
  }
 
  Collection c = new ArrayList();
  c.add(new String("aa"));
  c.add(new String("bb"));
  for(Object o : c){
               System.out.println(o);
  }
 
 
原文地址:https://www.cnblogs.com/yedushusheng/p/4354611.html