In AP Computer Science A, remove(int index) is the ArrayList method that deletes the element at the given index, shifts every later element one position left, shrinks the list's size by 1, and returns the removed object.
The remove method is one of the core ArrayList methods in the AP Java subset. Calling list.remove(index) does three things at once. It deletes the element sitting at that index, it slides every element after it one spot to the left to fill the gap, and it returns the object that was removed (you can use the return value or ignore it).
That left shift is the part that matters. An ArrayList never leaves holes, so after a remove, every element past the removed spot has a new index, and size() is one smaller. This is exactly what makes remove different from working with a plain array, where the length is fixed and you can't actually delete a slot. It's also what makes removing inside a loop dangerous. If you remove the element at index i and then increment i like normal, the element that just slid into position i never gets checked. The exam loves this bug.
The remove method lives in Unit 7 (ArrayList), where the CED expects you to call ArrayList methods, trace what they do to the list, and write algorithms that traverse and modify lists. Remove is the method that turns a simple traversal into a trap. The combination of shifting elements and a shrinking size means a loop that worked fine for get can silently skip elements once you add a remove call.
It also connects to error handling. Calling remove with an index that's negative or equal to size() throws an IndexOutOfBoundsException, which is one of the runtime exceptions the AP CSA exam expects you to recognize. So remove is really testing three skills at once: knowing the method's behavior, managing indices that move under you, and respecting the valid index range 0 to size() - 1.
IndexOutOfBoundsException (Unit 7)
This is the exception remove throws when the index is invalid. Valid indices for remove run from 0 to size() - 1, and since remove shrinks the list, an index that was legal on the last iteration of a loop might not be legal on this one.
Clear method (Unit 7)
clear() is remove on a grand scale. It empties the entire ArrayList in one call instead of deleting a single element at an index, and it returns nothing. If you only need to delete one element, remove is the tool; if you're wiping the whole list, clear is.
RemoveAll method (Unit 7)
Writing a removeAll algorithm with a loop and repeated remove calls is a classic AP exercise, and it's where the skip-an-element bug shows up. The standard fixes are to decrement i after a remove, only increment when you don't remove, or traverse the list backward.
ArrayIndexOutOfBoundsException (Unit 6)
Arrays throw their own out-of-bounds exception, but they have no remove at all. An array's length is fixed, so 'removing' from an array means manually shifting elements yourself. ArrayList's remove method automates exactly that shift, which is a big reason Unit 7 exists.
On the multiple-choice section, remove usually shows up as a code-tracing question. You're given a loop that removes elements matching some condition, and you have to figure out what the list looks like afterward. The most common trap mirrors a flawed removeAll method that loops forward with i++ after every iteration, even when an element was just removed. Because remove shifts elements left, consecutive matching values get skipped, so the code fails on lists like [3, 3, 5] when removing 3s. Watch for that pattern.
No released FRQ requires the word 'remove' in your answer, but ArrayList FRQs regularly ask you to write methods that delete elements meeting a condition, and a correct remove-with-index-adjustment loop is exactly what earns those points. When you trace or write this code, always ask two questions. Did the size just change? Did the indices just shift?
ArrayList actually has two remove methods, and they collide when the list holds Integers. list.remove(3) treats 3 as an index and deletes the element at position 3, not the value 3. The AP Java subset focuses on remove by index, so on the exam, assume the argument is an index unless the code clearly passes an object. If a question's list contains Integer values, read carefully to confirm whether the int is a position or a value.
remove(index) deletes the element at that index, shifts all later elements one position to the left, decreases size() by 1, and returns the removed object.
Removing inside a forward loop can skip elements, because the element that shifts into the removed slot never gets checked unless you adjust the index.
The standard fixes for the skip bug are decrementing i after a remove, only incrementing i when nothing was removed, or looping backward from size() - 1 to 0.
Calling remove with an index less than 0 or greater than or equal to size() throws an IndexOutOfBoundsException.
Unlike arrays, which have a fixed length, ArrayLists actually shrink when you remove, which is why size() and not a stored length must guide your loops.
remove deletes one element at a position, while clear() empties the entire list.
It deletes the element at the given index from an ArrayList, shifts every element after it one position left, reduces size() by 1, and returns the object that was removed. For example, on the list [4, 7, 9], calling remove(1) deletes 7 and leaves [4, 9].
Because remove shifts later elements left, the next element slides into the index you just processed. If your loop still does i++, that shifted element never gets checked. Fix it by doing i-- after a remove, only incrementing when you don't remove, or looping backward.
The element at index 3. With an int argument, Java calls remove(int index), even on an ArrayList
remove(index) deletes a single element at a specific position and returns it, while clear() deletes every element and returns nothing. After clear(), size() is 0; after one remove, size() drops by exactly 1.
Java throws an IndexOutOfBoundsException at runtime. Valid indices for remove are 0 through size() - 1, and since remove shrinks the list, an index that was valid earlier in a loop can become invalid later.