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);
}
}
}
}

 

你可能感兴趣的:(J2SE,J#)