增强for
 例:
  Collection coll = new ArrayList();
  coll.add(“abc1”);
  coll.add(“abc2”);
  coll.add(“abc3”);
正常for循环
  for(Iterator it = coll.iterator();it.hasNext();)
  {
      Object obj = it.next();
      System,out.println(obj);
  }
增强for语句写法
  for(Object obj : coll)
  {
     System,out.println(obj);
   }
数组同理(不使用角标的情况才会使用)
        int[] arr = {1,2,3,4};
        for(int x : arr)
        {   syso
           }
  格式: for(元素类型变量 :Collection容器or数组)
         {
            }
  区别:增强for必须有被遍历的目标,该目标只能是Collection或数组
  缺陷:只可以提取,不可以修改
如果是Map集合怎么办?1
2
3
4
5
6
7
8
9
10
11
12
13
14HashMap<Integer,String> hm = new HashMap<Integer,String>();
hm.put(1,"a");
hm.put(2,"b");
hm.put(3,"c");
Set<Integer> keySet = hm.keySet();
for(Integer i = keySet)
{
    syso(i+hm.get(i));
}
for(Map.Entry<Integer,String> me : hm.entrySet())
{
    syso(me.getKey()+me.getValue());
}