This gives error. Any other method to extract elements from a multi dimensional array one by one ?
I thought that for a foreach loop(variable holding corresponding value : array/Iterable), it is possible to first get the one dimensional array from a multiD. array and then create another foreach loop that extract elements from that array. But it gives all sorts of errors in foreach loop.
1st error: Array2D.java:14: error: not a statement for(a : arr[] )
Code Behind:
class Array2D {
public static void main(String[] args) {
int[][] array = new int[][]
{
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
int a[] = new int[3];
for(a : array) {
for(int n : a) {
System.out.print(n + " ");
}
}
}
}