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.
The .get() method is how you read an element out of an ArrayList in Java. You pass it an index (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. 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.
.get() lives in Topic 4.8 (ArrayList Methods) inside Unit 4: 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, 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.
Keep studying AP® Computer Science A Unit 4
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.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)
The generic type parameter E is what makes .get() type-safe. Declare ArrayList
Object reference (Unit 4)
An ArrayList stores object references, 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 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.
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.
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
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.
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.
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.
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.
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.
It returns the generic type E of the list. If you declared ArrayList
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
Review units, study guides, and course resources.
Check this vocabulary in multiple-choice context.
Apply key concepts in written AP responses.
Estimate the exam score you are working toward.
Review the highest-yield facts before practice.
Put the full course together before test day.