Two dimensional array initializer followed by square brackets
Solution 1:
What you are doing here is:
- Declaring a new variable
int[] it
(which is a one-dimensional array) - Assigning its value from the first element
[0]
- of the two-dimensional array
new int[][]
- which is initialized to be
{{1}}
So you create a two-dimensional array which you initialize to contain an array which contains 1
and at the same time you take the first element of the outer array (which is a one-dimensional array containing 1
) and assign it to your variable.
Solution 2:
int[] it = new int[][]{{1}}[0];
Let's break this one down into each stage, and what it means.
new int[][]
This is a new multidimensional array.
{{1}}
This is a multidimensional array literal. It makes an array that looks like this:
[0] = [1]
[1] = []
[2] = []
...
[N] = []
So take note, each element inside this array is itself an array. Then you've specified that your variable it
is equal to the first array in the multidimensional array, so it equates directly to:
int[] it = new int[] {1};