JDK1.5加入的增强for和循环. 新特性
举个例子:(1)
String[] number = {"1","2", "3", "4", "5","6" };
for (String i : number) {
System.out.print(i);
}
//结果会是123456
等价于(2) //正常手段的遍历数组
String[] number = {"1","2", "3", "4", "5","6" };
for (int i=0; i < number.length; i++) {
System.out.print( number[i]);
}
或者更贴切是这样的:(3)
String[] number = {"1","2", "3", "4", "5","6" };
for (int i=0; i < number.length; i++) {
String j = number[i];// 这个j,就等价与(1)中的 i
System.out.println(j);
}
这个结合集合的概念和同样是JDK1.5加入的泛性,可以做到简化代码的作用
|