I have a two dimensional array, e.g. String array[][] = {{"","","","","",},{"","","","","",}}
. This array is full and I want to resize it. So since arrays are fixed in size, I want to copy this array into a new, bigger array.
Also, I searched around the site and found that I can use
System.arraycopy()
and other methods but I prefer only using for loops. I was thinking a couple of for loops will suffice.
What I tried was:
String[][] newArray;
for(int i=0; i<array.length; i++) {
for(int j=0; j<array[i].length; j++)
newArray[i][j]=array[i][j];
System.out.println(newArray[i][j]);
System.out.println();
}
But I keep getting a compiling error saying error: cannot find symbol j
?
Also, I get the message variable newArray might not have been initialized
. Does newArray
must be initialized because I don't know what the size of it will be after my code is finished?