增强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循环。
|