码迷,mamicode.com
首页 > 其他好文 > 详细

增强for循环

时间:2021-02-15 12:35:46      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:++   demo   rgs   public   循环   for循环   增强   对象   数组   

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);
        }
    }
}

  

增强for循环

标签:++   demo   rgs   public   循环   for循环   增强   对象   数组   

原文地址:https://www.cnblogs.com/wchjdnh/p/14398066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!