An array allows multiple values to be accessed using a single variable name. Each element of an array is of the same type. The element type can be a simple primitive data type or a reference to an object.
One-dimensional arrays are allocated to a contiguous region of memory. This means that the elements of the array can be accessed efficiently as they are adjacent to each other. Arrays use an integer index to access an element in the array. Indexes range from 0 to the length of the array minus one. We are able to access the elements of an array directly, in any order as needed by the application, without having to visit each element.
Though Java supports multidimensional arrays, one-dimensional arrays are most commonly used. Arrays can be used for a variety of purposes including:
A collection of numbers representing ages
A list of employee names
A list of prices for an item in a store
The main disadvantage of arrays is that they have a fixed size. This makes it more difficult and less...