---
title: ".get() Method — AP Comp Sci A Definition & Examples"
description: "The .get() method returns the element at a given index in an ArrayList. Learn how it differs from array brackets and how AP CSA tests it in Unit 4."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/get-method"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 4"
---

# .get() Method — AP Comp Sci A Definition & Examples

## Definition

In AP Computer Science A, .get(int index) is the ArrayList method that returns the element stored at a given index without removing or changing it; for an ArrayList<E>, the return type is E, and calling it with an index outside 0 to size()-1 throws an IndexOutOfBoundsException.

## What It Is

The `.get()` [method](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") is how you read an element out of an ArrayList in Java. You pass it an [index](/ap-comp-sci-a/key-terms/index "fv-autolink") (an int), and it hands back a reference to the object stored at that position. It does not remove the element or change the list in any way. So `names.get(0)` gives you the first element, `names.get(names.size() - 1)` gives you the last one, and the list looks exactly the same afterward.

Because ArrayLists use generic types (EK 4.8.A.3), the type of whatever `.get()` returns matches the [type parameter](/ap-comp-sci-a/unit-4/arraylist-methods/study-guide/8juIkbLwLGELYtblBeCf "fv-autolink"). If you declared `ArrayList<String> names`, then `names.get(2)` returns a `String`, no casting needed. One more thing to remember from EK 4.8.A.1: an ArrayList holds object references, so `.get()` returns a reference to the object, not a copy of it. Valid indexes run from 0 up to `size() - 1`. Ask for anything outside that range and your program crashes with an `IndexOutOfBoundsException`.

## Why It Matters

`.get()` lives in Topic 4.8 (ArrayList Methods) inside [Unit 4](/ap-comp-sci-a/unit-4 "fv-autolink"): Data Collections, and it directly supports learning objective 4.8.A: developing code with ArrayList objects and determining the result of calling methods on them. You genuinely cannot do anything useful with an ArrayList without it. Every [traversal](/ap-comp-sci-a/key-terms/traversal "fv-autolink"), every search, every "find the max" or "count how many" algorithm on an ArrayList goes through `.get()` to read each element. Since Unit 4 algorithms show up heavily on both the multiple-choice section and the free-response questions, `.get()` is one of those small methods you'll type (and trace) dozens of times.

## Connections

### Array bracket notation (Unit 4)

Arrays and ArrayLists do the same job with different syntax. Where an array uses arr[i] to read an element, an ArrayList uses [list](/ap-comp-sci-a/key-terms/list "fv-autolink").get(i). Mixing these up is the single most common ArrayList syntax error on the exam, so train your eyes to match the data structure to its access syntax.

### [Generic type (Unit 4)](/ap-comp-sci-a/key-terms/generic-type)

The [generic type](/ap-comp-sci-a/key-terms/generic-type "fv-autolink") parameter E is what makes .get() type-safe. Declare ArrayList<String> and .get() returns a String the compiler can check at compile time instead of waiting for a run-time surprise. That's exactly why the CED says ArrayList<E> is preferred over plain ArrayList.

### [Object reference (Unit 4)](/ap-comp-sci-a/key-terms/object-reference)

An ArrayList stores [object references](/ap-comp-sci-a/key-terms/object-reference "fv-autolink"), so .get() returns a reference to the actual object in the list, not a copy. If you call a mutator method on what .get() returns, you're changing the object the list points to. That detail shows up in trickier code-tracing questions.

### ArrayList traversal with loops (Unit 4)

Standard ArrayList algorithms pair a for loop running from 0 to size() - 1 with .get(i) inside the body. Off-by-one errors here (like looping to size() instead of size() - 1) trigger IndexOutOfBoundsException, a favorite setup for "what does this code do?" multiple-choice questions.

## On the AP Exam

On the multiple-choice section, `.get()` shows up inside code segments you have to trace. A question might loop through an ArrayList calling `.get(i)` and ask for the output, or hide an off-by-one bug that throws an `IndexOutOfBoundsException`. You'll also see questions testing whether you know `.get()` reads without removing (unlike some methods that change the list). On the free response, any question involving an ArrayList expects you to access elements with `.get()`, since bracket notation doesn't compile on ArrayLists. Writing `list[i]` instead of `list.get(i)` is a classic point-loser, so make that distinction automatic before exam day.

## .get() method vs Array bracket notation (arr[i])

Both retrieve the element at an index, but the syntax is not interchangeable. Arrays use square brackets like arr[i], while ArrayLists require the method call list.get(i). Writing list[i] on an ArrayList is a compile-time error, and on an FRQ it costs you points. Quick rule of thumb: if you see ArrayList in the declaration, you're in method-call territory (get, set, add, remove); if you see square brackets in the declaration, you index with brackets.

## Key Takeaways

- The .get(int index) method returns the element at the given index of an ArrayList without removing it or changing the list.
- Valid indexes run from 0 to size() - 1, and calling .get() with any other index throws an IndexOutOfBoundsException.
- For an ArrayList<E>, .get() returns type E, which is why the CED prefers generic ArrayList<E> declarations that let the compiler catch type errors early.
- ArrayLists require list.get(i), while arrays use arr[i], and swapping the two syntaxes is a compile error that loses FRQ points.
- Because an ArrayList stores object references, .get() returns a reference to the actual object, so mutating that object changes what the list contains.

## FAQs

### What does the .get() method do in Java for AP CSA?

It returns the element stored at a specified index in an ArrayList. For example, names.get(0) returns the first element of names. It's part of Topic 4.8 (ArrayList Methods) in Unit 4 and supports learning objective 4.8.A.

### Does .get() remove the element from the ArrayList?

No. .get() only reads the element and leaves the list completely unchanged. If you want to remove an element, that's a different ArrayList method (remove), and exam questions love testing whether you know the difference.

### How is .get() different from using brackets like list[i]?

Brackets only work on arrays. ArrayLists are objects, so you access their elements through method calls, meaning list.get(i) instead of list[i]. Writing list[i] on an ArrayList won't compile, and it's one of the most common syntax mistakes on AP CSA free-response questions.

### What happens if I call .get() with an invalid index?

Java throws an IndexOutOfBoundsException at run time. Valid indexes go from 0 to size() - 1, so calling list.get(list.size()) is a classic off-by-one error that multiple-choice questions use as a trap.

### What type does .get() return from an ArrayList?

It returns the generic type E of the list. If you declared ArrayList<String> names, then names.get(i) returns a String. Per EK 4.8.A.3, using the generic form ArrayList<E> lets the compiler catch type errors that would otherwise crash your program at run time.

## Related Study Guides

- [4.8 ArrayList Methods](/ap-comp-sci-a/unit-4/arraylist-methods/study-guide/8juIkbLwLGELYtblBeCf)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/get-method#resource","name":".get() Method — AP Comp Sci A Definition & Examples","url":"https://fiveable.me/ap-comp-sci-a/key-terms/get-method","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/get-method#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:18.321Z","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/get-method#term","name":".get() method","description":"In AP Computer Science A, .get(int index) is the ArrayList method that returns the element stored at a given index without removing or changing it; for an ArrayList<E>, the return type is E, and calling it with an index outside 0 to size()-1 throws an IndexOutOfBoundsException.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/get-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 .get() method do in Java for AP CSA?","acceptedAnswer":{"@type":"Answer","text":"It returns the element stored at a specified index in an ArrayList. For example, names.get(0) returns the first element of names. It's part of Topic 4.8 (ArrayList Methods) in Unit 4 and supports learning objective 4.8.A."}},{"@type":"Question","name":"Does .get() remove the element from the ArrayList?","acceptedAnswer":{"@type":"Answer","text":"No. .get() only reads the element and leaves the list completely unchanged. If you want to remove an element, that's a different ArrayList method (remove), and exam questions love testing whether you know the difference."}},{"@type":"Question","name":"How is .get() different from using brackets like list[i]?","acceptedAnswer":{"@type":"Answer","text":"Brackets only work on arrays. ArrayLists are objects, so you access their elements through method calls, meaning list.get(i) instead of list[i]. Writing list[i] on an ArrayList won't compile, and it's one of the most common syntax mistakes on AP CSA free-response questions."}},{"@type":"Question","name":"What happens if I call .get() with an invalid index?","acceptedAnswer":{"@type":"Answer","text":"Java throws an IndexOutOfBoundsException at run time. Valid indexes go from 0 to size() - 1, so calling list.get(list.size()) is a classic off-by-one error that multiple-choice questions use as a trap."}},{"@type":"Question","name":"What type does .get() return from an ArrayList?","acceptedAnswer":{"@type":"Answer","text":"It returns the generic type E of the list. If you declared ArrayList<String> names, then names.get(i) returns a String. Per EK 4.8.A.3, using the generic form ArrayList<E> lets the compiler catch type errors that would otherwise crash your program at run time."}}]},{"@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":"Unit 4","item":"https://fiveable.me/ap-comp-sci-a/unit-4"},{"@type":"ListItem","position":4,"name":".get() method"}]}]}
```
