Array
An array is a collection of homogenous data stored at the contiguous memory locations. Each element is uniquely identified by its index value. An array is of a fixed size, once it is initialized with a number of an element is allowed then it won't add more than it's capacity.
Let's analyze the problem when we come up with this solution. Supposedly, you have to declare and initialize the same data type multiple variables in a program. What do you think, how easy could it be to remember all the names? To overcome these types of problems, we came with the solution of an array.
There are two types of array.
Three-Dimension Array (3D Array)
3D Array conceptually means that when you combine more than one 2D array, it becomes a 3D array. It works like depth * row * column. Therefore, you first select the depth and then row and then column.
NOTE:- All dimensional array is stored as a single dimension in actual memory. All the above are the virtual representation of the array for future reference.
Let's analyze the problem when we come up with this solution. Supposedly, you have to declare and initialize the same data type multiple variables in a program. What do you think, how easy could it be to remember all the names? To overcome these types of problems, we came with the solution of an array.
There are two types of array.
- Single Dimension Array
- Multi Dimension Array
- 2D Array
- 3D Array and so on.
Java supports 255 D Array but in actual we mainly focus on 1D and 2D Array.
One-Dimension Array (1D Array)
1D Array conceptually means that you have a single row with multiple columns and each column has the same size and they are contiguous by nature. In the example below, you can clearly see the index starts with 0 and the total element is 6.
1 | 2 | 3 | 4 | 5 | 6 | |
Index | 0 | 1 | 2 | 3 | 4 | 5 |
Two-Dimension Array (2D Array)
2D Array conceptually means that when you combine more than one 1D array, it becomes a 2D array. It looks like a matrix which is consist of rows and columns. If you want to select the value 10 and the name of the 2D array is arr. You will call arr[1][3] which means the first you select row and then column.
Index | 0 | 1 | 2 | 3 | 4 | 5 |
0 | 1 | 2 | 3 | 4 | 5 | 6 |
1 | 7 | 8 | 9 | 10 | 11 | 12 |
NOTE:- All dimensional array is stored as a single dimension in actual memory. All the above are the virtual representation of the array for future reference.
Comments
Post a Comment