Differences Between Array and ArrayList in Java

Last Updated : 13 Jan 2026

In Java, array and ArrayLists are well-known data structures. An array is a basic functionality provided by Java, whereas an ArrayList is a class of the Java Collections framework. It belongs to java.util package.

Java Array

An array is a dynamically created object. It serves as a container that holds a constant number of values of the same type. It has a contiguous memory location. Once an array is created, we cannot change its size. We can create an array by using the following statement:

The above statement creates an array of the specified size. When we try to add more than its size, it throws an ArrayIndexOutOfBoundsException. For example:

To read more Java Array

Example of an Array

In the following example, we have simply created an array of length four.

Example

Compile and Run

Output:

12
2
15
67

Java ArrayList Class

In Java, ArrayList is a class of the Collections framework. It implements List<E>, Collection<E>, Iterable<E>, Cloneable, Serializable, and RandomAccess interfaces. It extends the AbstractList<E> class.

We can create an instance of ArrayList by using the following statement:

An array in Java internally backs an ArrayList. The resize operation in ArrayList slows down the performance as it involves a new array and copying content from the old array to the new array. It calls the native implemented method System.arraycopy(sec, srcPos, dest, destPos, length).

We cannot store a primitive type in an ArrayList. So, it stores only objects. It automatically converts a primitive type to an object. For example, we have created an ArrayList object,

The JVM converts it into an Integer object through auto-boxing.

To read more Java ArrayList

Example of ArrayList

In the following example, we have created an instance of ArrayList and are performing iteration over the ArrayList.

Example

Compile and Run

Output:

12.4
34.6
56.8
78.9

Similarities

  • Array and ArrayList both are used for storing elements.
  • Array and ArrayList both can store null values.
  • They can have duplicate values.
  • They generally preserve the order of elements.

Array Vs. ArrayList

The following table describes the key differences between an array and an ArrayList:

BasisArrayArrayList
DefinitionAn array is a dynamically created object. It serves as a container that holds a constant number of values of the same type. It has a contiguous memory location.The ArrayList is a class of the Java Collections framework. It contains popular classes like Vector, HashTable, and HashMap.
Static/ DynamicAn array is static in size.ArrayList is dynamic in size.
ResizableAn array is a fixed-length data structure.ArrayList is a variable-length data structure. It can be resized itself when needed.
InitializationIt is mandatory to provide the size of an array while initializing it directly or indirectly.We can create an instance of ArrayList without specifying its size. Java creates an ArrayList of default size.
PerformanceIt performs fast in comparison to ArrayList because of its fixed size.An array in Java internally backs an ArrayList. The resize operation in ArrayList slows down the performance.
Primitive/ Generic typeAn array can store both object and primitive types.We cannot store a primitive type in an ArrayList. It automatically converts a primitive type to an object.
Iterating ValuesWe use a for loop or a foreach loop to iterate over an array.We use an iterator to iterate over an ArrayList.
Type-SafetyWe cannot use generics along with an array because it is not a convertible type of array.ArrayList allows us to store only generic/ type, so it is type-safe.
LengthArray provides a length variable that denotes the length of an array.ArrayList provides the size() method to determine the size of the ArrayList.
Adding ElementsWe can add elements to an array by using the assignment operator.Java provides the add() method to add elements to the ArrayList.
Single/ Multi-DimensionalAn array can be multi-dimensional.ArrayList is always single-dimensional.

Next TopicJava Tutorial