How about this?
List<Integer> arraylist0 = Arrays.asList(2,4,3);
List<Integer> arraylist1 = Arrays.asList(2,5,7);
List<Integer> arraylist2 = Arrays.asList(6,3,7);
List<List<Integer>> arraylistList = Arrays.asList(arraylist0, arraylist1, arraylist2);
int size = 3;
int[] myArray0 = new int[size];
int[] myArray1 = new int[size];
int[] myArray2 = new int[size];
int[][] myBigArray = new int[][] {myArray0, myArray1, myArray2};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
myBigArray[i][j] = arraylistList.get(j).get(i);
}
}
To explain, since we want to be able to work with an arbitrary size
(3, 15, or more), we are dealing with 2-dimensional data.
We are also dealing with array
and List
, which are slightly different in their use.
The input to your problem is List<Integer>
, and so we make a List<List<Integer>>
in order to deal with all the input data easily.
Similarly, the output will be arrays, so we make a 2-dimensional array (int[][]
) in order to write the data easily.
Then it's simply a matter of iterating over the data in 2 nested for
loops. Notice that this line reverses the order of i
and j
in order to splice the data the way you intend.
myBigArray[i][j] = arraylistList.get(j).get(i);
And then you can print your answer like this:
System.out.println(Arrays.toString(myArray0));
System.out.println(Arrays.toString(myArray1));
System.out.println(Arrays.toString(myArray2));