I don't know what type your Vectors are, but I'll assume they're Integer
s for now. Replace Integer
with whatever type you're using if you aren't.
If you're willing to use a Vector
instead of an array
, you can declare matrix like:
Vector<Vector<Integer>> matrix = new Vector<Vector<Integer>>();
And you can then add the elements like
matrix.add(vector1);
matrix.add(vector2);
matrix.add(vector3);
You'll then be able to access elements like
matrix.get(2).get(4); //Returns 6 from the sample data
If you really want to use arrays
, for whatever reason, it's still not hard to do, it's just another method from your vectors.
You would instead declare your matrix
like:
Integer[][] matrix = {vector1.toArray(), vector2.toArray(), vector3.toArray()};
Then you can access elements like
matrix[2][4]; //Returns 6 from the sample data
I will note, I'm not 100% that you'd need to do Integer[][]
instead of just int[][]
, but I think since you can't use primitives for your Vector
's generic you might have to keep on using Integer
.