Search code examples
javaarraysmultidimensional-arrayempty-list

Out of curiosity, is it possible to initialize a 0-by-1 array?


In Java, you can instantiate the following:

1-by-1 array: int[][] arr = {{0}};

1-by-0 array: int[][] arr = {{}};

0-by-0 array: int[][] arr = {};

 

Is a 0-by-1 array possible?


Solution

  • Java doesn't know multidimensional arrays, it does only know arrays which can contain other arrays, thus the result doesn't even have to be "rectangular" - the content arrays are independent of each other.

    So a 0-length "outer" array can't contain any inner array of length "1".