Basically, I want to create a 2-D array that grows in size at runtime. Could I do this using a vector in Java?
Would these be right then?
int [] [] x = new x [100] [100];
Vector x= new Vector();
To add elements into the array-
for i=0 to 99
for j=0 to 99
x.addElement(x[i] [j]);
essentially, it would be just the same like referencing any other object, only here, I’ve to specify the index numbers as well, right?
I’m a novice at Java. So I’d appreciate any help!
Unfortunately, Java has neither 2D arrays nor 2D growing vectors.
It has array of arrays or vector of vectors.
In your example, you created 1D vector of
Objects:is similar to growing array of type
Object[] xSo, when you do
Java does “boxing”, i.e. it does
Since you added 100×100 elements into 1D array, you will need to calculate location yourself
So, to avoid all this, use vector of vectors like example below. The example copies newly fixed size array into vector of vectors: