ArrayList constructor

In AP Computer Science A, the ArrayList constructor is the special method (called with new ArrayList<>()) that creates a new, empty ArrayList object ready to hold and resize a list of elements.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is the ArrayList constructor?

An ArrayList constructor is the call that actually builds an ArrayList object in memory. You write something like ArrayList<String> list = new ArrayList<String>(); (or the shorter new ArrayList<>(); once Java knows the type). The new keyword plus ArrayList<>() is the constructor in action. It hands you a brand-new, empty list, ready for add().

The <String> part is the generic type, telling the list what kind of object it will store. On the AP CSA exam, you'll see types like ArrayList<Integer>, ArrayList<String>, or ArrayList<SomeClass>. You can't use a primitive like int directly, so you use the wrapper class Integer instead. The constructor by itself makes the list with zero elements and size 0. Nothing is in there until you call add().

Why the ArrayList constructor matters in AP Computer Science A

The ArrayList is the AP CSA exam's go-to dynamic data structure, and the constructor is step one for using it. Unlike an array, where you fix the length when you create it, an ArrayList grows and shrinks as you add or remove elements. That flexibility is the whole point, and it starts at the constructor. Almost every FRQ involving a list of objects expects you to either be handed an ArrayList or build one yourself with the constructor before looping through it. Pair it with an import java.util.ArrayList; statement and you're set up for the methods that do the real work.

How the ArrayList constructor connects across the course

add() and get() (Unit 7)

The constructor builds the empty list; add() fills it and get() reads from it. Think of the constructor as setting up an empty shelf, and add()/get() as putting books on it and pulling them off. None of those methods do anything useful until the constructor has created the object first.

Import Statement (Unit 7)

Before you can call the ArrayList constructor, the compiler has to know what ArrayList is. That's what import java.util.ArrayList; does. The import brings the class into your file; the constructor then creates an instance of it.

size() (Unit 7)

A fresh ArrayList from the constructor has a size of 0. As you add() elements, size() climbs. Knowing the constructor starts you at empty is what makes off-by-one and bounds reasoning click on traversal questions.

Linear Search (Unit 7)

Once the constructor and add() have populated your ArrayList, a linear search walks through it index by index using get() and size(). The constructor is just the starting line for these traversal and search algorithms the exam loves.

Is the ArrayList constructor on the AP Computer Science A exam?

Expect ArrayList constructor calls all over Unit 7 multiple-choice questions and in the FRQ that asks you to manage a list of objects. On MCQs, you'll need to recognize correct syntax like new ArrayList<Integer>() and spot the difference between declaring a reference and actually constructing the object. On FRQs, you often have to declare and construct your own ArrayList, then loop through it with get() and size(). A common point of confusion graders see is forgetting that the constructor gives you an empty list, so writing get(0) right after constructing throws an exception. Always add() before you get().

The ArrayList constructor vs array declaration

An array fixes its length at creation, like int[] nums = new int[5];, and you can't change that 5. The ArrayList constructor makes a list with no fixed size that resizes itself as you add() or remove() elements. Both use the new keyword, but only the ArrayList grows on demand, and only the array uses square-bracket indexing like nums[0] instead of get(0).

Key things to remember about the ArrayList constructor

  • The ArrayList constructor is called with the new keyword, as in new ArrayList<String>(), and it returns a brand-new, empty list.

  • A freshly constructed ArrayList has a size of 0, so you must call add() before you can get() any element.

  • The generic type in angle brackets, like <Integer> or <String>, tells the list what type of object it holds, and you use wrapper classes instead of primitives.

  • You need import java.util.ArrayList; at the top of your file before the constructor will compile.

  • Unlike arrays, an ArrayList created by the constructor can grow and shrink, which is why the exam uses it for lists whose size isn't known ahead of time.

Frequently asked questions about the ArrayList constructor

What does the ArrayList constructor actually do?

It creates a new, empty ArrayList object in memory and gives you a reference to it. You write ArrayList<String> list = new ArrayList<String>();, and after that line you have a list with size 0 that's ready for add().

Does the ArrayList constructor put any elements in the list?

No. The constructor gives you an empty list with size 0. Nothing is in there until you call add(), which is why calling get(0) right after constructing throws an IndexOutOfBoundsException.

How is an ArrayList different from an array?

An array has a fixed length set when you create it, while an ArrayList can grow and shrink. Arrays use square brackets like nums[0]; ArrayLists use methods like get(0) and add(). Both use the new keyword to construct.

Why do I need an import statement to use the ArrayList constructor?

ArrayList lives in the java.util package, so the compiler doesn't know what it is until you add import java.util.ArrayList; at the top of your file. Without that import, the constructor won't compile.

Can I use int in an ArrayList, like ArrayList<int>?

No. ArrayList only holds objects, not primitives, so you use the wrapper class Integer instead: ArrayList<Integer>. Java's autoboxing then lets you add() plain int values, but the type in the angle brackets must be Integer.