以下是我再看别人的代码中发现的一种语法,自己平常没有用过,小弟不才,请高手指点一二,这种语法的执行过程是如何的?for (Component cellComp : cellComps) {
HeaderCellConstraints cell = compCellMap.get(cellComp);
if (cell == null) {
continue;
}int cellX = 0;
for (int i = 0; i < cell.x; i++) {
cellX += columnModel.getColumn(i).getWidth();
}int cellWid = 0;
for (int i = 0; i < cell.colSpan; i++) {
cellWid += columnModel.getColumn(cell.x + i).getWidth();
}int cellY = rowHeight * cell.y;
int cellHei = rowHeight * cell.rowSpan;cellComp.setBounds(cellX, cellY, cellWid, cellHei);
}

解决方案 »

  1.   

    for (Component cellComp : cellComps) JDK1.5的新特性中说明了冒号操作符代替 FOR循环语句的用法,其实就是遍历容器内的所有对象
      

  2.   

    这是5.0以后新增的一个foreach方法也叫增强的for循环!
    public static void read(int[] i){
    for(int j : i){        //这是5.0以后新增加的foreach方法!跟下面的方法作用一样!
    System.out.println(i);
    }
    for(int j ; j>i.length() ; j++)   //这是1.4以前我们读取数组中每一个元素的方法!
    {
    System.out.println(i[j]);
    }
    }
    我现在是在网吧没有eclipse所以格式和方法名也许有写的不是很准确的地方还请你见谅!如果想更多的了解的话可以去翻一下在线的String 和 Arrays的API文档!
      

  3.   

    相当于  C#  中的  foreach(int a in int[])
      

  4.   

    5.0以后新增的?我可是在JDK6.0里的,指示语法错误....
      

  5.   

    to k_52111() ,
    你好强,来网吧上CSDN....