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.
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
In the following example, we have simply created an array of length four.
Output:
12 2 15 67
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
In the following example, we have created an instance of ArrayList and are performing iteration over the ArrayList.
Output:
12.4 34.6 56.8 78.9
The following table describes the key differences between an array and an ArrayList:
| Basis | Array | ArrayList |
|---|---|---|
| Definition | 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. | The ArrayList is a class of the Java Collections framework. It contains popular classes like Vector, HashTable, and HashMap. |
| Static/ Dynamic | An array is static in size. | ArrayList is dynamic in size. |
| Resizable | An array is a fixed-length data structure. | ArrayList is a variable-length data structure. It can be resized itself when needed. |
| Initialization | It 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. |
| Performance | It 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 type | An 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 Values | We use a for loop or a foreach loop to iterate over an array. | We use an iterator to iterate over an ArrayList. |
| Type-Safety | We 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. |
| Length | Array provides a length variable that denotes the length of an array. | ArrayList provides the size() method to determine the size of the ArrayList. |
| Adding Elements | We can add elements to an array by using the assignment operator. | Java provides the add() method to add elements to the ArrayList. |
| Single/ Multi-Dimensional | An array can be multi-dimensional. | ArrayList is always single-dimensional. |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India