An array is a collection in java with similar types of elements that have a contiguous memory location.
In addition, special treatment is given to arrays in java as it is treated as an object which contains elements of a similar data type.
In addition, it is efficient to retrieve or sort the data with arrays and to access elements randomly.
It can store only a fixed set of elements. Therefore, it doesn’t grow its size at runtime. So we use the collection framework which grows automatically.
An array can contain primitives (int, char, etc) as well as to object (or non-primitive) elements.
Java array inherits the Object class and implements the Serializable as well as Cloneable interfaces.
Arrays in java can be classified as –
Single Dimensional Array
dataType[]Â a = {};
dataType[] a = new dataType[size];
dataType []a = {};
dataType []a = new dataType[size];
dataType a[] = {};Â
dataType a[] = new dataType[size];Â Â Â
Multi Dimensional Array
dataType[][]Â a = {{},{},{}};
dataType[][] a = new dataType[row size][column size];