`

foreach

阅读更多

J2SE 5.0新增了foreach的语法,又称强化的for循环(Enhanced for Loop),其应用的对象之一是在数组的依次存取上。foreach语法如下:

for(type element : array) { System.out.println(element)}

例:
public class Test2 {
public static void main(String[] args) {

int[][][] myArray = {{{1, 2},{3, 4}},{{5, 6},{7,8}}};

for(int[][] i : myArray) {
for(int[] j : i){
for(int k : j) {
System.out.println(k);
}
}
}
}

 

分享到:
评论
1 楼 幽奇猫 2011-01-12  
got it.
thx very much.

相关推荐

Global site tag (gtag.js) - Google Analytics