Java5新特性对数组的支持

增强for循环 → for-each

for (参数类型参数名 : 数组名) {

        代码块

}

Eg:

package reviewDemo;

public class Demo6 {

    public static void main(String[] args) {

        int []age = {1,2,3,69,36,636,459};

        for (int i : age) {

            System.out.println(i);

        }

    }

}  

这样就用for-each把数组遍历输出!

我的总结:for-each用于数组和Iterable对象!在以后的集合学习中还会经常用到for-each循环。

原文地址:https://www.cnblogs.com/fanweisheng/p/11131133.html