I am making an array2, i.e. array2 = {i,j}, and I have another 2D array e_list={} . Now I want to append array2 into e_list.
int[][] G = {{0, 0, 0, 1, 1},
{0, 0, 1, 1, 1},
{0, 1, 0, 0, 0},
{1, 1, 0, 0, 1},
{1, 1, 0, 1, 0},
};
int[][] e_list = {}; //<-initialize 2D array here
for (int i=0; i < 5; i++){
for (int j=0; j < 5; j++){
if (G[i][j] == 1){
int[] array2 = {i,j};
System.out.print(array2[1]);
System.out.print(",");
System.out.println(array2[0]);
//----------------------------//<-- here I want to add this array2 into that 2D array e_list
//this is one of my failed try;
for (int t=1; t <= 6; t++){
for (int tt=0; tt < 1; tt++){
e_list[t][tt] = array2[tt];
}
}
}
}
}
rite now the code simply prints the 1st and 2nd indexes of array2. but I want something like this; e_list = {{3,0}, {4,0}, ... , {1,2}} I want to access the e_list like, e_list[0][0] = 3, e_list[1][0] = 4 etc
I have tried the for loops inside ... but that did not worked.it says "java.lang.ArrayIndexOutOfBoundsException: 0"