+ 2
Multidimensional arrays in Java
I have this little doubt in Java arrays. If we define an array like * int[][] arr={{9,4},{8}}; * This is a two dimensional array. The number of elements is 3 or 4? If it's 3, how is that possible? Or, arrays implemented complex enough to handle that? If so, then how can I create an array of length 2, with each element being an array?. But the length of the first sub-array is 3 and the second sub-array is 2
1 Resposta
+ 1
int[][] arr={{9,4},{8}};
"The number of elements is 3 or 4?"
That array has 2 elements, each element is an array themselves.
"If it's 3, how is that possible? Or, arrays implemented complex enough to handle that?"
Not sure how to explain that. But to me, it looks like <arr> is an array of arrays, where each element of <arr> is allocated dynamically, allowing them to have different sizes.
"How can I create an array of length 2, with each element being an array?. But the length of the first sub-array is 3 and the second sub-array is 2"
https://code.sololearn.com/cfq4eCZHRjv3/?ref=app