ArrayList

AP Computer Science A · Unit 4: Data structures

ArrayList notes

Fact-checked by a second, independent AI review.

ArrayList is a resizable array-like collection in Java. It grows automatically as you add elements and supports indexed access and many convenience methods.

ArrayList
A dynamic array from java.util that automatically resizes as elements are added.
add / add(index, element)
Add elements to the end or insert at a specific index; shifts later elements right as needed.
get / set
get(index) retrieves; set(index, value) replaces the element at a given index.
size / remove / clear
size() returns count; remove(index) or remove(object) deletes elements; clear() empties the list.
generics / type safety
Use ArrayList<E> to enforce element type (e.g., ArrayList<String>); helps catch type errors at compile time.

Remember it: Remember: A List Grows—Add, Get, Remove, Size. If you get stuck, think in terms of index positions and how the list shifts after insertions/removals.

Exam tip: Examiners expect correct use of generics, proper method calls (add, get, set, remove, size), and awareness of IndexOutOfBounds when indexing. Practice tracing how size and indices change after each operation and explain complexity implications (O(1) for get/set, O(n) for add/remove in worst case).

Syllabus checklist

  • ArrayList: core ideas
  • Terms and typical exam questions for "Data structures" in AP Computer Science A (Java
  • College Board)

Practice questions

  1. 1. After adding 3 elements to an ArrayList, list.size() returns ____.

    Answer checked

    Show answer

    Answer: 3. size() reports the number of elements; adding three elements yields 3.

  2. 2. Which method removes by index in ArrayList?

    Answer checked

    Show answer

    Answer: remove(int index). remove(int index) removes the element at the given position.

  3. 3. To access the third element, use a blank: ____.

    Answer checked

    Show answer

    Answer: get(2). ArrayList indices start at 0; the third element is get(2).

  4. 4. ArrayList maintains insertion order.

    Answer checked

    Show answer

    Answer: True. ArrayList preserves the order in which elements were added.

Practise arraylist as a game

Hearts, combos, streaks and an AI tutor that explains every answer. Start free.

Start free

More from Unit 4: Data structures