In this article we are going to discuss about Arrays concept in Java.
Normally to store the data we use variables.And if the data we want to store is large and similar data it is difficulty to take that many variables.to control such cases Array concept is used.in this case we can maintain the data efficiently using the Arrays.
Array is a collection of similar data types.
Steps to create an Array.
- Declare an Array variable.
- Allocate the required number of Array size using new operator.
- Store the Address returned by the new operator in the Array variable.
In the above example we declared one dimensional array and with the size of 10 integer values. In the one dimensional Array to get number columns present in an Array use array_variable.length.
Syntax for Two dimensional Array is:
array_variable= new data_type[number of rows][number of columns]
Example: int book = new int ;
In this example we are storing the 3 rows and 10 columns into the book array.this example will useful if we want to store data of 3 books having the 10 pages each.To access number of rows in an Array a.length and to access number of columns in an Array use a[i].length where i is row number.