
foreach循环是一种加强型的for循环,主要用于简化数组或者集合数据的输出
传统的输出代码如下:
1 |
public class { |
传统的数组输出使用下标索引的方式实现数据的输出,从JDK 1.5开始for循环有了以下形式:
1 |
for(数据类型 变量:数组 | 集合){ |
public class testDeno6 {
public static void main(String args[]) {
int data[]=new int[]{4,5,6,8,9};
for(int x:data) {
System.out.println(x );
}
}
}`




近期评论