Variable number of two-dimensional arrays into one big array

Posted by qlb on Stack Overflow See other posts from Stack Overflow or by qlb
Published on 2010-04-01T17:50:49Z Indexed on 2010/04/01 17:53 UTC
Read the original article Hit count: 538

I have a variable number of two-dimensional arrays. The first dimension is variable, the second dimension is constant. i.e.:

Object[][] array0 = {
{"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
{"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
...
};

Object[][] array1 = {
{"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
{"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
...
};

...

Object[][] arrayi = ...

I'm generating these arrays with a for-loop:

 for (int i = 0; i < filter.length; i++) {
  MyClass c = new MyClass(filter[i]);
  //data = c.getData();
 }

Where "filter" is another array which is filled with information that tells "MyClass" how to fill the arrays. "getData()" gives back one of the i number of arrays.

Now I just need to have everything in one big two dimensional array. i.e.:

Object[][] arrayComplete = {
{"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
{"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
...
{"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
{"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
...
...
};

In the end, I need a 2D array to feed my Swing TableModel.

Any idea on how to accomplish this? It's blowing my mind right now.

© Stack Overflow or respective owner

Related posts about java

Related posts about multidimensional-array