Can someone explain this weird phenomenon?
Here goes:
int[][] arr = new int[1][5];
is declaring an int[][] and initializing it to a structure consisting of one top-level int[][] of length 1, and one second level int[] subarray of length 5. The first cell of the former refers to the latter.
Then:
arr[0] = Arrays.asList(values.split(" "))
.stream()
.mapToInt(Integer::parseInt)
.toArray();
is creating an int[] of length 6 and assigning it to arr[0]. This replaces the int[] subarray of length 5 that was created in the earlier initialization.
The intuitive behavior is that the "shape" of arr changes from a int[1][5] to int[1][6] when you do that assignment.
You then commented:
"Ohh basically then it treats as an array initialization rather than an assignment then."
Strictly, no. If you think of arr[0] = ... as an array initialization, it gets confusing. It is actually an assignment of a newly create array of type int[] to a cell of an existing "array of int[]".
This may sound like a fine distinction, but it goes to the heart of the matter. If you read the JLS and the JVM specs deeply, you will see that Java array types and objects are fundamentally one dimensional. Thus int[][] is a syntactic shorthand1 for "array of int[]", and arr[i][j] is a shorthand for (arr[i])[j].
Thus when we do arr[0] = ... in the example, we are not initializing something. Instead, we are changing a data structure that was initialized previously. At least, that is the Java language perspective.
From the perspective of the class where this is happening, this could be getting something into the initial state that is required by the class semantics. Thus it is reasonable to call that "initialization" ... from that perspective.
1 - This shorthand is so ingrained in the language that there isn't any other way to write the type "array of int[]" using Java syntax. The syntax for array types comes from C via C++, though the particular Java semantics of arrays doesn't.
a[0]is just a reference to an array, initialized to a new array of size 5. You change the reference to a new array of size 6.