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 › arraylist-size-method-in-java-with-examples
ArrayList size() Method in Java with Examples - GeeksforGeeks
July 11, 2025 - Example 2: Here, we use the size() method to get the number of elements in an ArrayList of strings. ... // Java program to demonstrate the use of // size() method for String ArrayList import java.util.ArrayList; public class GFG { public static void main(String[] args) { // Creating an ArrayList of Strings ArrayList<String> f = new ArrayList<>(); // Adding elements to the ArrayList f.add("Apple"); f.add("Banana"); f.add("Orange"); // Getting and printing the // size of the ArrayList int s = f.size(); System.out.println("" + s); } }
Discussions

how to set a maximum size for ArrayList?
Use an if statement and the size() of the ArrayList. More on forum.processing.org
🌐 forum.processing.org
May 20, 2013
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] Why is my ArrayList size always 0
Your ArrayList contains 0 elements, so the size is 0. Your top is also initially -1, so the expression top == stack.size() - 1 will evaluate to -1 == 0 - 1, which is always true (until something is added to the stack). You may be confusing size (number of elements in the current ArrayList) with the capacity (maximum number of elements allowed in the current ArrayList). In any case, if you're trying to write a stack for learning purposes, you'd probably get more out of it if you implemented it on a more basic level, and used an array internally instead of an ArrayList which basically has already implemented most of the logic for you. Alternatively, if you just need a stack, you should probably use java.util.Stack instead of re-implementing one. More on reddit.com
🌐 r/learnprogramming
7
5
February 26, 2017
[Java] How to write .size() method for an ArrayList?
Look ar ArrayList's implementation, create your own class, and implement the most useful methods(add,get,remove,size). It should be pretty straightforward. As you'll see, there is a private variable size, that increases and decreases when you add/remove an object. More on reddit.com
🌐 r/learnprogramming
16
7
April 30, 2013
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable · Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list.
🌐
TutorialsPoint
tutorialspoint.com › home › java/util › java arraylist size
Java ArrayList Size
September 1, 2008 - The following example shows the usage of Java ArrayList size() method. We're adding couple of Integers to the ArrayList object using add() method calls per element. Size of the arraylist is printed using size() method.
🌐
W3Schools
w3schools.com › java › ref_arraylist_size.asp
Java ArrayList size() Method
The size() method indicates how many elements are in the list. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want ...
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one).
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › ArrayList.html
ArrayList (Java SE 21 & JDK 21)
January 20, 2026 - The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation. Each ArrayList instance has a capacity.
🌐
Codecademy
codecademy.com › docs › java › arraylist › .size()
Java | ArrayList | .size() | Codecademy
January 27, 2023 - The .size() method of the ArrayList class returns the number of elements in the list. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-find-length-of-arraylist-in-java
How to find length of ArrayList in Java
September 11, 2022 - By using size() method of ArrayList class we can easily determine the size of the ArrayList. This method returns the number of elements of ArrayList.
🌐
Quora
quora.com › What-is-the-default-size-of-ArrayList-in-Java
What is the default size of ArrayList in Java? - Quora
Answer (1 of 3): The Default Size of ArrayList is 10 . Once ArrayList reaches its capacity a new ArrayList will be created with new capacity = ( current capacity * 3 /2 ) + 1 . Advantage : Array List is the Best Choice for Retrieval Operations ...
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-array-size-explained-by-example
Java array size, length and loop examples
The size or length count of an array in Java includes both null and non-null characters. Unlike the String and ArrayList, Java arrays do not have a size() or length() method, only a length property.
🌐
Quora
quora.com › What-is-the-difference-between-length-of-array-and-size-of-ArrayList-in-Java
What is the difference between length() of array and size() of ArrayList in Java? - Quora
Arrays and ArrayLists both hold ... public instance field of the array object (an int). ArrayList.size() is a public instance method that returns an int....
🌐
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);
    }
}
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › java arraylist length and size
Java ArrayList Length and Size
August 4, 2023 - An application can use this operation to minimize the storage of an ArrayList instance. The trim operation creates a new backing array with the 'size' attribute and stores the elements in the array.
🌐
Medium
medium.com › @qingedaig › java-initial-size-for-arraylist-in-different-java-version-9ed3cd8f8564
How does the size of ArrayList grow dynamically | by Alice Dai | Medium
July 30, 2025 - Default is 10 when the first element is added (Java 8+). Or whatever you specify in new ArrayList<>(initialCapacity). ... If the internal array is full (size == capacity), the ArrayList needs to grow.
🌐
iO Flood
ioflood.com › blog › length-of-arraylist-java
Java ArrayList Length: How to Get the Size of an ArrayList
February 27, 2024 - Then, we use the size() method to find the length of the ArrayList, which is 1 in this case. The size of the ArrayList is printed to the console. This is a basic way to find the length of an ArrayList in Java, but there’s much more to learn ...
🌐
Programiz
programiz.com › java-programming › library › arraylist › size
Java ArrayList size()
import java.util.ArrayList; class ...("ArrayList: " + primeNumbers); // get the number of elements of arraylist · int size = primeNumbers.size(); System.out.println("Length of ArrayList: " + size); } } // Output: ArrayList: [2, 3, 5, 7] // Length of ArrayList: 4...