黑马程序员技术交流社区

标题: Java5新特性对数组的支持 [打印本页]

作者: 小笨笨SHP    时间: 2016-2-21 21:53
标题: 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循环。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2