---
title: "Remove Method — AP Comp Sci A Definition & Exam Guide"
description: "The remove method deletes an ArrayList element at a given index, shifts everything left, and returns it. A top source of off-by-one bugs on the AP CSA exam."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/remove-method"
type: "key-term"
subject: "AP Computer Science A"
---

# Remove Method — AP Comp Sci A Definition & Exam Guide

## Definition

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.

## What It Is

The remove method is one of the core [ArrayList methods](/ap-comp-sci-a/unit-4/arraylist-methods/study-guide/8juIkbLwLGELYtblBeCf "fv-autolink") in the AP Java subset. Calling `list.remove(index)` does three things at once. It deletes the element sitting at that [index](/ap-comp-sci-a/key-terms/index "fv-autolink"), 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](/ap-comp-sci-a/unit-4/developing-algorithms-using-arraylists/study-guide/MKbteieYvLOpWIwfqiND "fv-autolink") 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.

## Why It Matters

The remove method lives in Unit 7 (ArrayList), where the CED expects you to call ArrayList methods, trace what they do to the [list](/ap-comp-sci-a/key-terms/list "fv-autolink"), and write algorithms that traverse and modify lists. Remove is the [method](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") 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](/ap-comp-sci-a/key-terms/indexoutofboundsexception "fv-autolink"), 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.

## Connections

### [IndexOutOfBoundsException (Unit 7)](/ap-comp-sci-a/key-terms/indexoutofboundsexception)

This is the [exception](/ap-comp-sci-a/key-terms/exception "fv-autolink") 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](/ap-comp-sci-a/key-terms/algorithm "fv-autolink") 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)](/ap-comp-sci-a/key-terms/arrayindexoutofboundsexception)

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 AP Exam

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?

## remove method vs remove(Object) vs remove(int index)

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.

## Key Takeaways

- 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.

## FAQs

### What does the remove method do in AP Comp Sci A?

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].

### Why does removing in a loop skip elements?

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.

### Does remove(3) remove the value 3 or the element at index 3?

The element at index 3. With an int argument, Java calls remove(int index), even on an ArrayList<Integer>. This trips people up constantly, so on the exam, treat an int argument to remove as an index.

### What's the difference between remove and clear?

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.

### What happens if I call remove with a bad index?

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.

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/remove-method#resource","name":"Remove Method — AP Comp Sci A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/remove-method","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/remove-method#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T00:50:33.139Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/remove-method#term","name":"remove method","description":"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.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/remove-method","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What does the remove method do in AP Comp Sci A?","acceptedAnswer":{"@type":"Answer","text":"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]."}},{"@type":"Question","name":"Why does removing in a loop skip elements?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"Does remove(3) remove the value 3 or the element at index 3?","acceptedAnswer":{"@type":"Answer","text":"The element at index 3. With an int argument, Java calls remove(int index), even on an ArrayList<Integer>. This trips people up constantly, so on the exam, treat an int argument to remove as an index."}},{"@type":"Question","name":"What's the difference between remove and clear?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"What happens if I call remove with a bad index?","acceptedAnswer":{"@type":"Answer","text":"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."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"remove method"}]}]}
```
