I have this array:
String[][] hej = {{"9.8", "0", "hi", "0"}, {"0", "3.4", "yes", "no"}};
And I want to create a new array without all the zeros.
I started to create a new array:
String[][] zero = new String[hej.length][hej[0].length];
I have tried to only insert the elements which are not zeros with this for loop:
for(int c = 0; c < zero.length; c++) {
int i = 0;
if(hej[i][c] != "0") {
zero[i][c] = hej[i][c];
But it doesn't work and I cannot understand why.
If I do it without a for loop it's like this: ` if(hej[0][0] != "0") zero[0][0] = hej[0][0];
if(hej[0][1] != "0")
zero[0][1] = hej[0][1];
if(hej[0][2] != "0")
zero[0][2] = hej[0][2];
if(hej[0][3] != "0")
zero[0][3] = hej[0][3];`
But then I still don't know how to make the array shorter without the spot for the removed zero.
Anyone who can help me understand why my for loop doesn't work and how I can make a for loop to go through the whole [][] array?
Anyone who can help me understand how to at the same time create a new dynamic array without the spots from the zeros?
Thanks!