I want to build a 2D array from N (one-dimensional) arrays. The only problem is, as far as I can tell, the only way to declare a multi-dimensional array in Java requires you to specify all inner dimension sizes, and those sub-arrays get created. In this case, this seems wasteful, since they will be overwritten
In C++, I could do this:
Object** arr = new Object*[n];
for(int i=0;i<n; ++i)
{
arr[i] = getObjArr();
}
In Java, you have to say this:
Object[][] arr = new Object[n][0]; //inner dimension is required
Each of those n zero-length arrays will be created, only to get overwritten as the array is populated. Is there a way to declare a multi-dimensional array (similar to the pointer to pointer(s) syntax of C) without allocating the inner arrays?