An array has a fixed length after creation, whereas an ArrayList is a resizable collection. In Java, List is an interface describing list behaviour, while ArrayList is one class that implements that interface.
Under B2.2 Data structures, both are linear structures: elements are stored in an ordered sequence and normally accessed using an index, beginning at 0. The major difference is how their size and operations are managed.
| Feature | Array | ArrayList / List |
|---|---|---|
| Size | Fixed when created | Can grow or shrink during execution |
| Element access | Direct indexed access, such as scores[2] | Indexed access through a method, such as scores.get(2) |
| Adding or removing | Must usually be implemented by shifting elements or creating another array | Provided through methods such as add() and remove() |
| Stored values in Java | Can directly store primitive values or object references | Stores object references; wrapper classes such as Integer are used for primitive-like values |
| Type meaning | A concrete built-in data structure | List is an interface; ArrayList is a concrete implementation |
| Typical strength | Predictable size and low overhead | Flexibility when the number of elements changes |
For example, int[] marks = new int[30]; creates exactly 30 positions. By contrast, List<Integer> marks = new ArrayList<>(); creates a list to which values can be added as needed. Declaring the variable as List<Integer> supports abstraction because code depends on the list interface rather than one particular implementation.
A common misconception is that List and ArrayList are two unrelated data structures. In Java, List specifies operations, while ArrayList supplies their implementation using an internal resizable array.
Exam technique: For a compare question, state both a similarity and clear differences. Link the choice to the scenario: use an array when the number of elements is known and fixed; use an ArrayList when insertions, removals, or changing size are required.