Arrays in Java

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 control such cases Array concept is this case we can maintain the data efficiently using the Arrays.
Array is a collection of similar data types.

Steps to create an Array.

  1. Declare an Array variable.
  2. Allocate the required number of Array size using new operator.
  3. Store the Address returned by the new operator in the Array variable.


		int array_variable[];
		array_variable=new int[10];
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.

Two-dimensional Array

Syntax for Two dimensional Array is:

data_type array_variable[][];

array_variable= new data_type[number of rows][number of columns]
Example: int book[][] = new int [3][10];

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.

Three-dimensional Array

Leave a Reply

Your email address will not be published. Required fields are marked *