Part 17 – Java Arrays (2D arrays)
August 2, 2020 1 min read

2D (two-dimensional) array is a multidimensional array. A multidimensional array is an array of arrays. 3D array also a multidimensional array, but rarely using. Today we are going to learn about 2D arrays.
Before we learn about 2D arrays, make sure you know about java arrays. You can follow the link given below to study about java arrays.
2D array means an array that can stores address of another array. Let’s study about it using an example.


Here you can see the statements given have commands only to give marks for one student. But those commands are given according to the order of creating elements in the array object to input marks from subject to subject. Also we can give only one command to print the marks for subjects using a for-loop without making commands for each subject.
output:

You can write 2D arrays as in the given below example also.

Try the following example.

Here in the 1st command of printing line given to print the value of “xr” variable. But no value given for that. So it will print the array address. In the 2nd line given to print the value of “xr[0]” row. But there is no value for the column. Therefore it will print the address of the row. In the 3rd line given to print the value of 1st row and the column of the 2D array. So it will print as 0. In the next 2 lines you can see the output coming for the length of elements and the length of the 1st row.
Output:

Java basics are over from this article. If you have any doubt on java basics or want to know any topic, leave a comment. Let’s meet with a new tutorial on “OOP Concepts”.
Thank you.


