An array in Java is a way of storing multiple elements of the same data type without manually maintaining a variable for each. These elements can be accessed using a numbered index, starting from 0 (Farrell, 2016). One can also iterate over elements, modifying them or accessing their methods (Farrell, 2016). However, if using an array to store objects, one still needs to initialize them by calling the constructor for each individual object (Farrell, 2016). Thus, one can use this structure when a program needs to store multiple instances of similar objects or values, especially if similar actions should be performed on multiple elements at the same time.
An array should not be used when the data types that need to be stored are different. For instance, it makes little sense to store employee data and sales items data together. Two arrays would need to be created for such an application. Furthermore, an array is not needed when the amount of similar values is reasonably low and they can be named meaningfully, such as the coordinates of a rectangle’s corners.
A critical limitation of the array is its fixed size: once initialized, elements cannot be added to or removed from it. This makes arrays difficult to use for data whose amount can change. For example, a warehouse application might require the array storing those items to be reinitialized often as items are added or removed. To address this problem, the ArrayList class was created; this class is largely similar to an array, but it is resizable. As such, this class should be used in situations where one expects data elements that would otherwise be stored in an array to be added or removed often. However, ArrayLists perform slower than arrays, making the use of the latter preferable in cases where data is unlikely to be added or removed often.
Reference
Farrell, J. (2016). Java Programming (8th ed.). Boston, MA: Cengage Learning.