请问使用foreach语句可以遍历二维数组吗?请举例子。

解决方案 »

  1.   


    int[][] arr = new int[4][4]; for(int[] a : arr) {
    for(int b : a) {
    System.out.println(b);
    }
    }
      

  2.   

    public class Tem{
    public static void main (String[] args) {
    int[][] t={{1,2,3,4},{5,6,7,8}};
    for(int[] t1:t){
    for(int t2:t1){
    System.out.print(t2+" ");
    }

    }
    }

    }
      

  3.   

    是可以的.. 只要实现了Iterable<T>这个接口的都能用迭代器去做循环遍历
      

  4.   

    可以,但不要这么去做使用 foreach 语句去遍历数组的效率是极其低下的