What is Array in Java?

Array is like a Basket. We carried basket when we are going to market. In a basket we can store apple, banana, vegetables etc. Here array is same like basket.

In array we can store homogeneous (Similar type) type of data. An array is an indexed collection of homogeneous data element (value). Every value is store in array based on indexed. In array we can store multiple values.

Advantage of Array

Disadvantage of Array

Types of Arrays

4 types of array are in Java Language

1D or Single Dimensional Array

In single dimensional array we can store only single data type value. Single variable but one ( [ ] ) subscript.

We can't initialize the size of array at the time of declaration.

In two ways we can initialize the 1D array

2D Array

In 2D or multi dimensional array we can store multilple data value with single variable in the form of row and column with two ( [row][column] ) subscript. Array brackets are called subscript.

In java 2D array implemented as an array of array.

Advantage of 2D array

In two ways we can initialize the 2D array

3D Array

In 3D or multi dimensional array we can store multilple data value with single variable in the form of row and column with three ( [ ][ ][ ] ) subscript. Array brackets are called subscript.

Very rare case people use 3D Array. Mostly we use 1D or 2D array in Java. In java 3D array implemented as an array of array

In two ways we can initialize the 2D array

Anonymous Array

Some time we create an array in java without name such type nameless array called anonymous array.

Why we create anonymous array in java?

Syntax:


	new data-type[] {elements};

Example of Anonymous array:


	//pending

Output


	//pending
    
Advertisement here

Share this Page.