I'm not able to understand the following multi-dimensional code. Could someone please clarify me?
int[][] myJaggedArr = new int [][]
{
new int[] {1,3,5,7,9},
new int[] {0,2,4,6},
new int[] {11,22}
};
May I know how it is different from the following code?
int[][] myArr = new int [][] {
{1,3,5,7,9},
{0,2,4,6},
{11,22} };
It's not different at all. The former just makes it more explicit that you're creating an array of arrays.
No real difference. Just the first is declaring the sub arrays while the second is just placing values that are arrays into the array
The two pieces of code produce identical results.
Multidimensional arrays are arrays of arrays.
myArr[0][1]
would return 3myArr[1][1]
would return 2myArr[2][0]
would return 11If 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