V Bose

Ranch Hand

Posts: 113

posted 14 years ago

Aim : Create a 2 dimensional array data structure @ runtime.

Premise : New to Java!

What I tried :

int i=0;

Vector Correlation;

Correlation = new Vector();

while (i < NRows)

{

Correlation.addElement(new Vector());

i++;

}

((Vector)Correlation.get(0)).add("10"); //Correlation[0][0]=10

((Vector)Correlation.get(0)).add("5"); //Correlation[0][1]=5

Question 1 : Is there another(less painful) way I can simulate a flexible, m-dimensional array @ runtime.

Question 2 : Am I using the right way to access the Vector of Vectors in Correlation

Premise : New to Java!

What I tried :

int i=0;

Vector Correlation;

Correlation = new Vector();

while (i < NRows)

{

Correlation.addElement(new Vector());

i++;

}

((Vector)Correlation.get(0)).add("10"); //Correlation[0][0]=10

((Vector)Correlation.get(0)).add("5"); //Correlation[0][1]=5

Question 1 : Is there another(less painful) way I can simulate a flexible, m-dimensional array @ runtime.

Question 2 : Am I using the right way to access the Vector of Vectors in Correlation

posted 14 years ago

What you're doing is basically sound. To make it less painful, you would encapsulate the whole thing in a class. This class could use Vector in its implementation, or it might even just use arrays.

The class (call it Matrix) could have methods like

Then you could say

Finally: note that there is a

The class (call it Matrix) could have methods like

Then you could say

Finally: note that there is a

*very*strongly respected coding standard that says Java variable names should begin with a lowercase letter; writing "Correlation" with an uppercase letter makes your code harder to read for those of us who are used to reading Java code.
V Bose

Ranch Hand

Posts: 113