Java中的增强型for循环

下面是关于增强型for循环对一维数组与二维数组遍历的具体实现:

public class NewForLoop {
    public static void main(String[] args) {
       	int[] arr=new int[]{1,2,3,3,2,1,3,3,3};
       	int[][] ar=new int[][]{{1,22,31},{12,34,45},{112,32,45}};
       	for(int n:arr)//for增强版遍历一维
       		System.out.print(" "+n);
       		System.out.println("
---------------------------");
       	for(int[] n:ar)//for增强版遍历二维
       		for(int n1:n)
       			System.out.print(" "+n1);
    }
}

原文地址:https://www.cnblogs.com/tfxz/p/12621766.html