In AP Computer Science A, an index is the integer position of an element inside a data structure like an array, ArrayList, or String. Java uses zero-based indexing, so the first element is at index 0 and the last is at length - 1 (or size() - 1 for an ArrayList).
An index is the number Java uses to label each position in an ordered collection. In an array, arr[0] is the first element and arr[arr.length - 1] is the last. In an ArrayList, you reach positions with list.get(i), and in a String, charAt(i) and substring(i, j) work the same way. All three start counting at 0, not 1, which is called zero-based indexing.
The single most useful mental model is that an index counts how many elements come BEFORE a position. Index 0 means zero elements come before it, so it's the first element. That's why a structure with 5 elements has valid indices 0 through 4, and why asking for index 5 crashes your program. Index mistakes are the source of two of the most-tested bugs in the course, the off-by-one error and the out-of-bounds exception.
Indexing is the connective tissue of Units 6 through 8 (arrays, ArrayLists, and 2D arrays) and shows up earlier with String methods in Units 1-2 and indexed for loops in Unit 4. Almost every array or ArrayList question on the exam is secretly an index question. You need to know that valid indices run from 0 to length - 1, that 2D arrays use a row index followed by a column index (arr2D[row][col]), and that ArrayList methods like add(index, element) and remove(index) shift every later element, changing what index each one lives at. The exam loves traversal code where the loop bounds, the index arithmetic, or a mid-loop insertion is the whole point of the question. If you can trace indices accurately, a huge slice of the MCQ section opens up.
Zero-based Indexing (Units 6-8)
This is the core convention behind every index in Java. The first element is at 0 and the last is at length - 1, which is exactly why the loop condition i < arr.length uses < and not <=.
ArrayIndexOutOfBoundsException (Unit 6)
This runtime exception is what happens when an index goes wrong. Access index -1 or index equal to arr.length and Java throws it. The ArrayList version, IndexOutOfBoundsException, is its sibling in Unit 7.
Indexed for loop (Unit 4)
The standard for (int i = 0; i < arr.length; i++) pattern exists to walk through indices one at a time. An enhanced for loop hides the index, which is exactly why you can't use it when you need to modify elements by position.
remove method (Unit 7)
Calling list.remove(i) deletes the element at index i and shifts everything after it left by one. If you remove inside a loop without adjusting i, you skip the element that just slid into the hole. That trap is an exam favorite.
Index knowledge gets tested constantly, just rarely by name. MCQs give you traversal code and ask what prints, and the answer choices are built around index mistakes, like starting at 1 instead of 0, using <= instead of <, or forgetting that add(i, value) shifts later elements. Practice questions in this style include tracing nums.remove(nums.size() - 2) (which removes 30 from [10, 20, 30, 40], since size() - 2 is index 2) or predicting an ArrayList after numbers.add(2, 25) slots 25 in at index 2 and pushes 30, 40, and 50 right. On FRQs, indices are the workhorse. The 2018 FRQ Q4 had you extract a column from a 2D array using a valid column index, the 2019 LightBoard question required row and column indexing across a 2D structure, and the 2017 Phrase and 2021 WordMatch questions leaned on String index methods like indexOf and substring. When you write FRQ code, getting the loop bounds right (0 to length - 1, or to length - substring length when comparing chunks) is often worth multiple rubric points.
The index is the position; the element is the value stored at that position. In int[] arr = {50, 60, 70}, the index 1 holds the element 60. Exam answer choices often swap these, for example offering the index where a max occurs when the question asked for the max value itself. Always check whether the question wants the position or the thing at the position.
An index is the integer position of an element in an array, ArrayList, or String, and Java starts counting at 0.
Valid indices run from 0 to length - 1 for arrays and Strings, and from 0 to size() - 1 for ArrayLists.
Using an index outside that range throws an ArrayIndexOutOfBoundsException (arrays) or IndexOutOfBoundsException (ArrayLists) at runtime.
ArrayList add(index, element) and remove(index) shift later elements, so the index of every element after that point changes.
2D arrays use two indices, row first and column second, so arr2D[r][c] means row r, column c.
Most off-by-one bugs come from mixing up < and <= in loop conditions or forgetting the last index is length - 1, not length.
An index is the numbered position of an element in an ordered structure like an array, ArrayList, or String. Java is zero-based, so the first element sits at index 0 and the last at length - 1.
No. The last valid index is arr.length - 1, not arr.length. Accessing arr[arr.length] throws an ArrayIndexOutOfBoundsException, and this exact off-by-one trap appears in MCQ answer choices.
An index identifies one position, while length is the total number of elements. A 5-element array has length 5 but indices 0 through 4, which is why the two values are always off by one.
The numbering is identical (zero-based, last index is one less than the count), but the syntax differs. Arrays use brackets like arr[2] and arr.length, while ArrayLists use methods like list.get(2) and list.size().
No. Unlike Python, Java does not support negative indexing, so arr[-1] does not mean the last element. It throws an ArrayIndexOutOfBoundsException, and the exam expects you to know that.