How can I fill a multidimensional array in Java without using a loop? I\'ve tried:
double[][] arr = new double[20][4];
Arrays.fill(arr, 0);
how can I fill a multidimensional array in Java without using a loop?
Multidimensional arrays are just arrays of arrays and fill(...)
doesn't check the type of the array and the value you pass in (this responsibility is upon the developer).
Thus you can't fill a multidimensional array reasonably well without using a loop.
Be aware of the fact that, unlike languages like C or C++, Java arrays are objects and in multidimensional arrays all but the last level contain references to other Array
objects. I'm not 100% sure about this, but most likely they are distributed in memory, thus you can't just fill a contiguous block without a loop, like C/C++ would allow you to do.