34 - Multi-Dimensional (2D) Arrays in Java (Hindi/Urdu)
LIKE, SHARE & SUBSCRIBE
Multi-Dimensional Arrays (2D Arrays) are known as Arrays of Arrays.
It means that we can create and store the information (reference name) of different arrays in a single array and it acts as a parent array. A single array can have multiple child arrays.
We use multi-dimensional arrays for basically two reasons :
1) Arranging our data set in a proper indexed manner so to improve the code readability.
2) Memory Optimisation of our code so that our data get stored more efficiently.
While declaring a two-dimensional array we use two square brackets ( [ ] [ ] ).
int[ ][ ] testArray = new int[2][2];
testArray[0][0] = 1 ;
testArray[0][1] = 2 ;
testArray[1][0] = 3 ;
testArray[1][1] = 4 ;
This shows that we are creating a 2-dimensional array. And in this 2-D array, we have saved 1, 2, 3, 4 integer values.
In these two square brackets, we provide the size for parent and child arrays.
But sometimes we don't know the size of our child arrays. In that case we "Jagged Arrays", in which we don't provide the size of child arrays.
int[ ][ ] testArray = new int[2][ ];
testArray[0] = new int[3] ;
testArray[1] = new int[4] ;
Here we are creating two child arrays. The size of the first child is 3 and the size of the second child is 4.
We can also declare, define and create objects in the two-dimensional array by using a single statement.
We also use length functionality in arrays so that we easily iterate without providing any explicit value in our for loops.
We can also access the name of our array data type by adding array-name.getClass() and we can also we see the simplified name by adding array-name.getClass().getSimpleName().
Thanks for watching & stay tuned.
Video link for the single-dimensional array: https://youtu.be/zZTAaTDoHkI
Like us on Facebook - https://goo.gl/y7oxYc
Follow us on Twitter - https://goo.gl/UKmTfn
Видео 34 - Multi-Dimensional (2D) Arrays in Java (Hindi/Urdu) автора Учимся программировать с нуля
Видео 34 - Multi-Dimensional (2D) Arrays in Java (Hindi/Urdu) автора Учимся программировать с нуля
Информация
4 декабря 2023 г. 19:53:12
00:42:16
Похожие видео