You can't, basically. A "multi-dimensional" array is just an array of arrays. So you have to know the size of the "outer" array to start with, in order to create it.
So your options are:
- Use the array in an inverted way as
array[column][row]
instead ofarray[row][column]
Use a list instead, so you can add new rows as you go:
List<Object[]> rows = new ArrayList<Object[]>(); for (SomeData data : someSource) { Object[] row = new Object[5]; ... rows.add(row); }
(Or even better, encapsulate your concept of a "row" in a separate class, so you have a
List<Row>
.)