增强for循环
时间:2021-02-15 12:35:46
收藏:0
阅读:0
public class demo3 {
public static void main(String[] args) {
// 增强for循环 <=> 数组或者集合对象的语法糖
int[] arr = {1,2,3,4,5,6};
// 最笨的方法
for(int i = 0; i < arr.length; i++){
System.out.println("这是" + i);
}
// 语法糖
for(int x:arr){
System.out.println("这是" + x);
}
}
}
评论(0)