Here we will differentiate Between One Dimension And Two Dimensional Array. Where one Dimensional Array array stores the list of a data type where all the elements are stored in a single row or in a way that all the elements have an index number as an integer.
Whereas when we talk about two dimension array it is stored as a matrix or we can say in rows and columns where the elements are being stored in two digits where the first digit is a row and the second digit a column number.
Let’s understand it in a better way.
One Dimension
It is a simple array where we store the data as the elements in a single row where each element have an index number in a single number, to understand it in better ways look at the example given below.
datatype variable _name[] = new datatype[ size]; ------------ option 1 to decleare the one dimension array array Or datatype[] variable _name = new datatype[ size];
Here we can see how we can declare one Dimension array in two different ways where we can give square brackets either before the name of a variable or after the variable name, But it is recommended to use square brackets after the variable.
Although using a square bracket after the name of the variable is also correct in java and in C++ we use it as after only but in java, it is recommended to use it before the variable..
Two Dimension
Two dimensions can be visual by looking at a matrix or a table that stores the homogeneous data for example a table of marks of students, But it does not store the name of the column as it can store the data of homogeneous data.
To understand it and declare follow the example given below.
class ABC { public static void main(String[] args) { int[][] integer2DArray; // 2D integer array String[][] string2DArray; // 2D String array double[][] double2DArray; // 2D double array boolean[][] boolean2DArray; // 2D boolean array float[][] float2DArray; // 2D float array double[][] double2DArray; // 2D double array } }
Here are some examples of two- dimensional arrays declare with different data types to understand them better.
To learn more about java at Java Tutorials By Prakhar Yadav To learn more about the solutions of java and also follow How To Reverse A String In Python? to learn more about python problems.
To learn more about two Dimensional arrays visit Two Dimensional Array.