How to declare one dimensional array and multi dimensional array in Java?

In Java, array is a group of variables having the same type. You can access an array element by using an index.  To declare an array:

type variable_name[ ];

To allocate memory in an array, use syntax:

array_variable = new type[size];

A multidimensional array is an array of arrays. For Example: 3 dimensional array

type name[ ][ ][ ] = new type[a][b] [c];

Array can also be declared as:

type[ ] variable_name;

Leave a Reply