How to place successive matrices in vector

Asked

Viewed 47 times

1

I have the following matrices of 100 elements:

int [][]matriz1 = {       {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,1,0,0,0},
                          {0,0,0,0,0,0,1,0,0,0},
                          {0,0,0,0,1,1,1,0,0,0},
                          {0,0,0,0,1,0,0,0,0,0}};


int [][]matriz2 = {       {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,1,0,0,0,0,0},
                          {0,0,0,1,1,1,0,0,0,0},
                          {0,0,0,0,1,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0},
                          {0,0,0,0,0,0,0,0,0,0}};

As I step to matriz1 and matriz2 to a vector? At vector position 0 is the matriz1 and at position 1 is matriz2.

  • I just wonder if this is really necessary, since it has better and simpler resources to deal with collections. This question looks like a XY problem

  • I need to create pre-defined boards.But to choose 1 random I have to use a Rand function for those who are inserted and return a board

  • And just because you need to create trays, you think you need to use it there? There are easier ways to represent this, but to do so, you’d need to explain better what you’re doing and show what you’ve done with a code that is [mcve]. Perhaps it is a case of another question.

1 answer

1


In Java, matrices are actually arrays of arrays. That is, an array in which each element is another array.

Then, to place these arrays in another array, just make an "array of arrays", ie an "array of arrays of arrays":

int[][][] v = { matriz1, matriz2 };

So, v is the array you wanted, being that v[0] contains matriz1 and v[1] contains matriz2.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.