增强for循环

public class demo3 {
    public static void main(String[] args) {
        // 增强for循环,也叫forEach遍历  <=> 数组或者集合对象的语法糖
        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);
        }
    }
}

  

posted @ 2021-02-11 19:40  火鸡的呐喊  阅读(33)  评论(0编辑  收藏  举报