Let's say I have a 2D array:
int[][] a = new int[4][3];
populated such that:
1 2 3
4 5 6
7 8 9
2 5 7
Is there any shortcut method in java to extract lets say column 1 as single array:
array1 = {1 4 7 2};
Currently what I am doing is traversing through the whole 2D matrix and with if condition (if j==0
), I traverse over the rows and add values to 1D array.
Just wondering if there is any standard method offered in java for such tasks.