Java beginner here. I have 2 string arrays A
, B
. for a new empty array C
, I'd like to assign each value in A
B
to C
. Code I've got as following:
String[] A = {"banana", "orange", "apple"};
String[] B = {"2", "3"};
String[][] C;
private String[][] mix() {
for (int i = 0; i < this.A.length; i++) {
for (int j = 0; j < this.B.length; j++) {
C[i][j] = {A[i], B[j]};
}
}
The above code gives me error on C[i][j] = {A[i], B[j]};
:
Array constants can only be used in initializers
EDIT: my expected output would be
C = {{"banana", "2"}, {"orange", "2"}, {"apple", "2"}, {"banana", "3"}, {"orange", "3"}, {"apple", "3"}}
or any permutation like above with all 6 combinations.