Java Multi Dimensions Array - Java Tutorials

Java Multi Dimensions Array - Java Tutorials

Java Multi Dimensions Array - Java Tutorials

Multidimensional Arrays in Java

In java, the grouping of same type of elements for storing under the same
name is done using array.An array can hold any type of data and can have
multidimensional. For accessing elements of array we use its index.

In other words, we can say that array is the set of same type of data stored
under the same roof.

Given below the example to provide you an idea-how array works?

Declaring one dimension array

type var-name[ ];

For example :

int[] Dev ;

or , you can also declare it as follows :

int Dev[];

If an array is declared as : int Dev[3], it means it has 4 element from Dev[0] to Dev[3].

Allocating memory to arrays :

var-name = new type[size];

Example :

Dev = new int[12];

Assigning and accessing value from array

You can assign value directly, like this :

Dev[0] = 12; // this will assign value to first element.Dev[1] = 30
// this will assign value to second element.