PrepGo

AP Computer Science A Flashcards: ArrayList Methods

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Review key ideas with interactive flashcards. This set includes 10 cards to help you master important concepts.

What value does the `size()` method return?
The `size()` method returns the number of elements currently in the ArrayList.
Card 1 of 10

All Flashcards (10)

What value does the `size()` method return?
The `size()` method returns the number of elements currently in the ArrayList.
What are the two primary characteristics of an ArrayList object?
An ArrayList object is mutable in size, meaning it can grow or shrink, and it contains references to other objects.
An `ArrayList` of Integers called `nums` contains `[10, 20, 30]`. What value is returned by the call `nums.set(2, 40)`?
The call returns the integer `30`, which was the original element at index 2 before it was replaced.
In the declaration `ArrayList<E>`, what does the type parameter `E` specify?
The type parameter `E` is a generic type that specifies the specific type of the elements that the ArrayList will store.
What does the `set(int index, E obj)` method do and what does it return?
The `set` method replaces the element at a given index with a new element and returns the original element that was replaced.
An `ArrayList` has a size of 5. What is the result after the method `remove(0)` is called on this list?
The element at index 0 is removed, and the size of the `ArrayList` becomes 4.
An `ArrayList` of Strings called `words` contains `["A", "B", "C"]`. What is the result of calling `words.add(1, "X")`?
The element "X" is inserted at index 1, and the `ArrayList` becomes `["A", "X", "B", "C"]`.
What is the difference between `add(E obj)` and `add(int index, E obj)`?
The `add(E obj)` method appends an element to the end of the list, while `add(int index, E obj)` inserts an element at a specified index.
What is the result of calling the `remove(int index)` method?
The `remove` method deletes the element at the specified index, shifts subsequent elements, and returns the element that was removed.
What is the function of the `get(int index)` method?
The `get(int index)` method retrieves and returns the element located at the specified index without modifying the list.