You're confusing the size of the array list with its capacity:

  • the size is the number of elements in the list;
  • the capacity is how many elements the list can potentially accommodate without reallocating its internal structures.

When you call new ArrayList<Integer>(10), you are setting the list's initial capacity, not its size. In other words, when constructed in this manner, the array list starts its life empty.

One way to add ten elements to the array list is by using a loop:

for (int i = 0; i < 10; i++) {
  arr.add(0);
}

Having done this, you can now modify elements at indices 0..9.

Answer from NPE on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › initialize-an-arraylist-in-java
Initialize an ArrayList in Java - GeeksforGeeks
July 11, 2025 - ArrayList inherits the AbstractList class and implements the List interface. ArrayList is initialized by a size, however, the size can increase if the collection grows or shrink if objects are removed from the collection.
Discussions

ArrayList default initialization size
Because index 5 is out of range. The starting size of 10 means that the array under the hood has a size of 10. Thats just so that it doesnt need to be resized immediately. It does not mean that you can add something to those later indexes. Think about it, by your logic an empty list would return a size of 10. More on reddit.com
🌐 r/javahelp
9
5
November 23, 2022
java - How to initialize an ArrayList with a certain size and directly access its elements - Stack Overflow
I was writing something that needs an arrayList of size n, so I did the following: List (n); And when I was trying to access an More on stackoverflow.com
🌐 stackoverflow.com
Why isn't initializing ArrayList size working? - Processing 2.x and 3.x Forum
Hi there. According to the java docs I can declare an ArrayList with an initial size: public ArrayList(int initialCapacity) Yet when I execute this: More on forum.processing.org
🌐 forum.processing.org
java - Initialization of an ArrayList in one line - Stack Overflow
I don't understand why we cannot ... 4, 5} in Java. Create and init a mutable array in one line, as I know Python and Swift could do that. ... It would be simpler if you were to just declare it as a fixed-size List (but with mutable elements) - does it have to be an ArrayList... More on stackoverflow.com
🌐 stackoverflow.com
🌐
freeCodeCamp
freecodecamp.org › news › how-to-initialize-an-arraylist-in-java-with-values
How to Initialize an ArrayList in Java – Declaration with Values
April 21, 2023 - You'll see the different in-built methods that can be used to add, access, modify, and remove elements in an ArrayList. Let's get started! The terms "declaration" and "initialization" are commonly associated with data structures. Declaration has to do with creating a data structure, while initialization involves assigning values to the data structure. ... import java.util.ArrayList; public class ArrayListTut { public static void main(String[] args) { ArrayList<String> people = new ArrayList<>(); } }
🌐
W3Docs
w3docs.com › java
Initial size for the ArrayList
The initial size of an ArrayList in Java is 0. The ArrayList class is a resizable array implementation of the List interface, which means that the size of the ArrayList can grow or shrink as needed to accommodate the elements added to or removed ...
🌐
Reddit
reddit.com › r/javahelp › arraylist default initialization size
r/javahelp on Reddit: ArrayList default initialization size
November 23, 2022 -

I'm reading that an ArrayList has a default size of 10 once initialized. If that is the case why does the following code throw IndexOutOfBoundsException ?

public class Test {
    public static void main(String[] args) {
        List list = new ArrayList < > ();
        list.add(0,"ONE");
        list.add(1, "TWO");
        list.add(5, "THREE");

        System.out.println(list);
    }
}
🌐
Baeldung
baeldung.com › home › java › java array › the capacity of an arraylist vs the size of an array in java
The Capacity of an ArrayList vs the Size of an Array in Java | Baeldung
November 11, 2025 - Below are some major differences between the size of an array and the capacity of an ArrayList. Arrays are fixed size. Once we initialize the array with some int value as its size, it can’t change.
🌐
Medium
medium.com › @mertercan › should-we-specify-the-initial-size-of-an-arraylist-in-java-5a948aadd52d
Should we specify the initial size of an ArrayList in Java? | by Naci Mert ERCAN | Medium
July 31, 2022 - If we initialize a large array list, we avoid the grow operation, on the other hand when the array list size is bigger than the maximum size, grow operation may allocate lots of memory because of the newCapacity() method.
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java arraylist: how to declare, create, initialize arraylist
Java ArrayList: How to Declare, Create, Initialize ArrayList
March 5, 2026 - This overloaded constructor can be used to create an ArrayList with the specified size or capacity provided as an argument to the constructor. ... The above statement creates an empty ArrayList named ‘arraylist’ of type Integer with capacity 10. The third overloaded constructor for the ArrayList class takes an already existing collection as an argument and creates an ArrayList with the elements from the specified collection c as its initial elements.
Find elsewhere
🌐
Processing Forum
forum.processing.org › two › discussion › 24562 › why-isn-t-initializing-arraylist-size-working.html
Why isn't initializing ArrayList size working? - Processing 2.x and 3.x Forum
Is there not a way java can automatically assume that I want my array initialized with PVector elements, instead of just creating blank slots that I need to fill by hand? ... I could be wrong, but I suspect you are not approaching this problem in the right way. An array ([]) is given a fixed size on declaration, and you manage that. However, part of the entire point of an ArrayList is that its capacity is almost always an internal implementation detail -- an ArrayList automatically makes itself bigger as you add things, so you usually don't and shouldn't care what it is doing internally.
🌐
TutorialKart
tutorialkart.com › java › java-create-arraylist-of-specific-size
How to Create an ArrayList of Specific Size in Java?
December 21, 2020 - The size we mentioned is just the initial capacity with which the ArrayList is created. But, it does not limit you from adding elements beyond the size N, and expand the ArrayList. In the following program, we will create an ArrayList of strings with size 3. ... import java.util.ArrayList; public class ArrayListExample { public static void main(String[] args) { ArrayList<String> names = new ArrayList<String>(3); names.add("Google"); names.add("Apple"); } }
🌐
TutorialsPoint
tutorialspoint.com › how-do-i-set-the-size-of-a-list-in-java
How do I set the size of a list in Java?
June 10, 2025 - import java.util.ArrayList; import ... list.size()); } } ... Let's create a list with a specific size using the Collections.nCopies() method....
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › initialize an arraylist in java
Initialize an ArrayList in Java
August 4, 2023 - Using the ArrayList constructor is the traditional approach. We initialize an empty ArrayList (with the default initial capacity of 10) using the no-argument constructor and add elements to the list using add() method.
🌐
Siditaduli
siditaduli.com › java › initializing-list-in-java
Java made easy: Initializing List in Java - Blog - Sidita Duli
March 23, 2025 - In this example, we’re initializing an ‘ArrayList’ of integers with three elements: 1, 2, and 3. We use the ‘add()’ method to add elements to the list. The advantage of using ‘ArrayList’ for dynamic initialization is that it automatically resizes itself as elements are added or removed.
🌐
TutorialsPoint
tutorialspoint.com › article › initialize-an-arraylist-in-java
Initialize an ArrayList in Java
March 18, 2025 - In this article, we will learn to initialize an ArrayList in Java. The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed. Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged.
🌐
iO Flood
ioflood.com › blog › java-initialize-arraylist
Initialize an ArrayList in Java: Easy and Advanced Methods
February 27, 2024 - The simplest way to initialize an ArrayList is with the syntax: ArrayList<String> list = new ArrayList<String>(); which creates an empty ArrayList named ‘list’ that can hold String objects.
🌐
Codemia
codemia.io › knowledge-hub › path › initial_size_for_the_arraylist
Initial size for the ArrayList
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
Top answer
1 of 16
2789

It would be simpler if you were to just declare it as a fixed-size List (but with mutable elements) - does it have to be an ArrayList?

List<String> places = Arrays.asList("Buenos Aires", "Córdoba", "La Plata");

Or if you have only one element:

List<String> places2 = Collections.singletonList("Buenos Aires");

This would mean that places2 is immutable (trying to change it in any way will cause an UnsupportedOperationException exception to be thrown).

To make a variable-size list that is a concrete ArrayList you can create an ArrayList from the fixed-size list:

ArrayList<String> places = new ArrayList<>(Arrays.asList("Buenos Aires", "Córdoba", "La Plata"));

And import the correct package:

import java.util.Arrays;
2 of 16
2240

Actually, probably the "best" way to initialize the ArrayList is the method you wrote, as it does not need to create a new List in any way:

ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");

The catch is that there is quite a bit of typing required to refer to that list instance.

There are alternatives, such as making an anonymous inner class with an instance initializer (also known as an "double brace initialization"):

ArrayList<String> list = new ArrayList<String>() {{
    add("A");
    add("B");
    add("C");
}};

However, I'm not too fond of that method because what you end up with is a subclass of ArrayList which has an instance initializer, and that class is created just to create one object -- that just seems like a little bit overkill to me.

What would have been nice was if the Collection Literals proposal for Project Coin was accepted (it was slated to be introduced in Java 7, but it's not likely to be part of Java 8 either.):

List<String> list = ["A", "B", "C"];

Unfortunately it won't help you here, as it will initialize an immutable List rather than an ArrayList, and furthermore, it's not available yet, if it ever will be.

🌐
HelloKoding
hellokoding.com › create-and-initialize-an-arraylist-in-java
Initialize an ArrayList in Java
March 28, 2020 - Internally, an ArrayList is backed by a fixed size array. When its capacity is full, Java needs to create a new array with larger capacity and copies old items to that · @Test public void initWithCapacity() { List<Integer> arrayList = new ArrayList<>(1000); for (int i = 0; i < 1000; i++) { arrayList.add(i); } assertThat(arrayList).hasSize(1000); } In this tutorial, we learned some ways to create and initialize ...
🌐
Squash
squash.io › how-to-initialize-an-arraylist-in-one-line-in-java
How to Initialize an ArrayList in One Line in Java - Squash Labs
November 3, 2023 - Here are two possible approaches: You can use the Arrays.asList() method to initialize an ArrayList in one line. This method takes a variable number of arguments and returns a fixed-size List backed by the specified array.