Languages Comparisonbeginner

Array vs ArrayList in Java: Differences

An array has a fixed size and can hold primitives; an ArrayList grows on its own but holds only objects. See the differences in a table with short Java code.

5 min read

Our verdict in 30 seconds

An array in Java has a fixed size set when you create it and can store primitives like int directly. An ArrayList is a class from java.util that grows and shrinks as you add or remove items, gives ready methods like add, remove and contains, but stores only objects, so int values are boxed to Integer. Use an array when the size is known and fixed; use an ArrayList when the number of items changes.

On This Page

Array vs ArrayList in Java is one of the first comparisons you meet after learning loops. An array is a basic language feature: a fixed-size block that holds values of one type. An ArrayList is a class in java.util that wraps an array and resizes it for you. The short rule: if the number of items is fixed, an array is fine; if items keep coming and going, use an ArrayList.

Array vs ArrayList: the comparison table

Point Array ArrayList
What it is Built-in language feature Class in java.util (part of the Collections Framework)
Size Fixed when created Grows and shrinks automatically
Stores primitives (int, double) Yes, directly No; stores objects such as Integer
Stores objects Yes Yes
Get the size arr.length (a field) list.size() (a method)
Read an item arr[i] list.get(i)
Change an item arr[i] = x list.set(i, x)
Add an item Not possible after creation list.add(x)
Remove an item Not possible; shift items by hand list.remove(...)
Ready methods Few (helpers in java.util.Arrays) Many: add, remove, contains, indexOf, sort
Multi-dimensional Yes, int[][] Only by nesting lists
Memory and speed Lighter, slightly faster for primitives Small overhead for objects and spare capacity
Type safety Checked at runtime Checked at compile time with generics

The same task in both

Store three marks, add a fourth, remove one, and print the result:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArrayVsArrayList {
    public static void main(String[] args) {
        // Array: fixed size, set when created
        int[] marks = new int[3];
        marks[0] = 72;
        marks[1] = 85;
        marks[2] = 64;
        System.out.println("Array: " + Arrays.toString(marks) + ", length " + marks.length);

        // ArrayList: grows and shrinks
        List<Integer> scores = new ArrayList<>();
        scores.add(72);
        scores.add(85);
        scores.add(64);
        scores.add(90);                       // no size limit
        scores.remove(Integer.valueOf(85));   // remove by value
        System.out.println("ArrayList: " + scores + ", size " + scores.size());
        System.out.println("First score: " + scores.get(0));
    }
}

Output:

Array: [72, 85, 64], length 3
ArrayList: [72, 64, 90], size 3
First score: 72

With the array, adding a fourth mark is impossible. You would have to create a new, bigger array and copy the old values. The ArrayList does that copying for you behind the scenes.

What happens when you go past the size

Arrays do not grow. Writing to index 3 of a 3-element array stops the program:

public class OutOfBounds {
    public static void main(String[] args) {
        int[] marks = new int[3];
        marks[3] = 90;
    }
}

Output:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
	at OutOfBounds.main(OutOfBounds.java:4)

Valid indexes are 0, 1 and 2. An ArrayList also throws an exception if you call get with an index that does not exist, but add never runs out of room.

Primitives: why ArrayList fails

Generics in Java work only with objects. So this does not compile:

ArrayList<int> nums = new ArrayList<>();

The compiler says:

error: unexpected type
  required: reference
  found:    int

Use the wrapper class instead: ArrayList<Integer>. Java converts between int and Integer automatically (autoboxing). Each Integer is a small object, which is why a large int[] uses less memory than an ArrayList<Integer> of the same length.

Common mistake: Calling remove(1) on an ArrayList<Integer> and expecting it to remove the value 1. With an int argument, Java picks remove(int index), so it removes the item at index 1.

import java.util.ArrayList;
import java.util.List;

public class RemoveTrap {
    public static void main(String[] args) {
        List<Integer> nums = new ArrayList<>(List.of(10, 20, 30));
        nums.remove(1);                    // removes the element at index 1
        System.out.println(nums);
        nums.remove(Integer.valueOf(10));  // removes the value 10
        System.out.println(nums);
    }
}

Output:

[10, 30]
[30]

Converting between the two

You will often get data as an array and need a list, or the other way round:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Convert {
    public static void main(String[] args) {
        String[] cities = {"Hyderabad", "Pune", "Chennai"};

        // array -> ArrayList
        List<String> list = new ArrayList<>(Arrays.asList(cities));
        list.add("Bengaluru");
        System.out.println(list);

        // ArrayList -> array
        String[] back = list.toArray(new String[0]);
        System.out.println(back.length + " " + back[3]);
    }
}

Output:

[Hyderabad, Pune, Chennai, Bengaluru]
4 Bengaluru

Wrapping Arrays.asList(...) in new ArrayList<>(...) matters. Arrays.asList alone returns a fixed-size list, so calling add on it throws UnsupportedOperationException.

How ArrayList grows inside

An ArrayList keeps a normal array plus a count of how many slots are used. When you add an item and the array is full, it creates a larger array (in OpenJDK, about 1.5 times the old size) and copies everything across. Copying is slow, but it happens rarely, so adding at the end is fast on average.

If you know roughly how many items are coming, you can set a starting capacity: new ArrayList<>(1000). This avoids repeated copying. Capacity is not the same as size; size() still returns 0 until you add items.

ArrayList advantages, and when an array is still better

ArrayList advantages

  • no need to know the size in advance
  • ready methods for add, remove, search and sort
  • works with the rest of the Collections Framework, streams and for-each
  • prints neatly with System.out.println(list)

When an array is the better choice

  • the size is fixed, such as 12 months or a 9 by 9 board
  • you need a large block of primitives, such as a million int values
  • you work with a 2D grid (int[][]) in DSA problems
  • a method you call expects an array, such as main(String[] args)

Which should you use? Choose array if / choose ArrayList if

Choose an array if

  • the number of items is known and will not change
  • you store many primitive values and memory matters
  • you solve a coding problem that gives input as an array

Choose an ArrayList if

  • items are added or removed while the program runs
  • you want built-in methods instead of writing loops by hand
  • you are writing application code, such as a list of students or orders

In real Spring Boot or backend code, List<...> backed by an ArrayList is far more common than raw arrays. In DSA rounds, arrays appear constantly. Learn both well.

Where to go next

Revise the basics in our Java arrays lesson, then go deeper with the ArrayList guide. If you want the next comparison interviewers ask, read ArrayList vs LinkedList. For the data structure view outside Java, see array vs linked list, and practise with Java collections interview questions.

Interview note: A clear answer is: "An array has a fixed size and can hold primitives. An ArrayList is a resizable list from the Collections Framework that holds only objects and gives methods like add and remove. Internally, ArrayList uses an array and grows it when full." Then mention length versus size() to show you have written both.

Frequently Asked Questions

Which is faster, array or ArrayList?
Reading by index is fast in both because an ArrayList uses an array inside. A plain int array is usually a little faster and uses less memory, because ArrayList stores Integer objects instead of raw int values. For most student programs the difference does not matter.
Can an ArrayList store int values?
Not directly. ArrayList<int> does not compile. Use ArrayList<Integer>. Java converts int to Integer and back for you, which is called autoboxing and unboxing.
How do I find the size of an array and an ArrayList?
An array uses the length field, written marks.length with no brackets. An ArrayList uses the size() method, written list.size(). Mixing these up is a common compile error.
Is ArrayList the same as a dynamic array?
Yes, in idea. An ArrayList keeps an internal array. When it fills up, it creates a bigger array and copies the items across. That is why adding at the end is fast most of the time.
Should I use ArrayList or LinkedList?
ArrayList is the usual default because index access is fast. LinkedList is a different structure with its own trade-offs. See our ArrayList vs LinkedList page for the full comparison.

Want to Build Your Career in Java Full Stack with AI?

Join CodeBegun and train with working industry engineers — Check the Java Full Stack training details

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 5 December 2026 LinkedIn

More comparisons

View all
Chat with us