第二种for循环 for (循环变量类型 循环变量名称 : 要被遍历的对象) 循环体

for (循环变量类型 循环变量名称 : 要被遍历的对象) 循环体
借助这种语法,遍历一个数组的操作就可以采取这样的写法:

清单3:遍历数组的简单方式

复制代码 代码如下:

/* 建立一个数组 */
int[] integers = {1, 2, 3, 4};

/* 开始遍历 */
for (int i : integers) {
System.out.println(i); /* 依次输出“1”、“2”、“3”、“4” */
}

这里所用的for循环,会在编译期间被看成是这样的形式:

https://www.cnblogs.com/jtlgb/p/6202718.html

猜你喜欢

转载自blog.csdn.net/qq_36547531/article/details/81209001