Why does this code compile?
int[] array = new int[][]{{1}}[0];
On the left side is one-dimensional array. On the right I thougth that three-dimensional, but it is not?
The right side is a one dimensional array that is the first (0th) element of the two-dimensional array
new int[][]{{1}}
To show it out more clearly lets add parenthesis
int[] array = (new int[][]{{1}}) [0];// [0] is returning first row of 2D array
// which is 1D array so it can be assigned to `array`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With