Two dimensional array initializer followed by square brackets
arrays, compilation, java
Solution
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.
Problem
I have a problem understanding this piece of code: ``` int[] it = new int[][]{{1}}[0]; ``` Why is it compileable, and how can I understand such a declaration?