Top Array Mistakes That Cost You Points on the AP CSA Exam

Unit 4 — Exam Critical

Top Array Mistakes That Cost You Points on the AP CSA Exam

These are the errors that show up on every exam. Learn to spot them before they cost you points on May 15.

AP CSA Exam: May 15, 2026. Arrays and ArrayList account for 30–40% of the exam. Fix these mistakes now.

Mistake #1

Off-by-One: Using <= Instead of <

The single most common array error on the AP CSA exam. An array of length 5 has valid indices 0 through 4. Using <= in the loop condition tries to access index 5, which does not exist.

WRONG
int[] data = {10, 20, 30, 40, 50};
for (int i = 0; i <= data.length; i++)
{
    System.out.println(data[i]);
}

This throws ArrayIndexOutOfBoundsException on the last iteration when i equals 5.

CORRECT
int[] data = {10, 20, 30, 40, 50};
for (int i = 0; i < data.length; i++)
{
    System.out.println(data[i]);
}
Exam pattern: The AP exam loves to show you a loop with <= and ask what happens. The answer is always a runtime error. If you see <= with .length or .size(), flag it immediately.

Mistake #2

Confusing .length With .size()

Arrays use .length (no parentheses — it is a field, not a method). ArrayList uses .size() (with parentheses — it is a method call). Mixing them up is a compile-time error.

WRONG
int[] nums = {1, 2, 3};
System.out.println(nums.size());   // compile error

ArrayList words = new ArrayList();
System.out.println(words.length);  // compile error
CORRECT
int[] nums = {1, 2, 3};
System.out.println(nums.length);   // 3

ArrayList words = new ArrayList();
words.add("hello");
System.out.println(words.size());  // 1
Memory trick: Array = built-in structure = .length field. ArrayList = object with methods = .size() method. If it has parentheses, it is a method call. The exam frequently places the wrong one in a code snippet and asks you to identify the error.

Mistake #3

Using == Instead of .equals() for Strings in Arrays

When you compare String objects in an array, == checks if they are the exact same object in memory. .equals() checks if the characters match. On the exam, they are almost never the same object.

WRONG
String[] names = {"Ana", "Ben", "Cal"};
String target = new String("Ben");
for (int i = 0; i < names.length; i++)
{
    if (names[i] == target)
    {
        System.out.println("Found at " + i);
    }
}
// Prints nothing — == compares references, not content
CORRECT
String[] names = {"Ana", "Ben", "Cal"};
String target = new String("Ben");
for (int i = 0; i < names.length; i++)
{
    if (names[i].equals(target))
    {
        System.out.println("Found at " + i);
    }
}
// Prints: Found at 1
Exam trap: The AP exam will show code that uses == for Strings and ask what happens. The method appears to “not find” the target even though the value exists in the array. Always use .equals() for String comparison.

Mistake #4

Trying to Modify Array Elements With an Enhanced For Loop

The enhanced for loop gives you a copy of each element’s value. Assigning to the loop variable does not change the original array.

WRONG
int[] scores = {70, 80, 90};
for (int s : scores)
{
    s = s + 10;  // modifies the LOCAL copy only
}
// scores is still {70, 80, 90}
CORRECT
int[] scores = {70, 80, 90};
for (int i = 0; i < scores.length; i++)
{
    scores[i] = scores[i] + 10;
}
// scores is now {80, 90, 100}
Rule: Use a standard for loop when you need to modify elements or know the index. Use an enhanced for loop only when you need to read every element without changing anything. The exam tests this distinction directly.

Stop Losing Points to Preventable Mistakes

The 4-Week Cram Kit gives you a day-by-day plan to eliminate these errors before May 15.

Get the Cram Kit — $29.99 1-on-1 Tutoring

Mistake #5

Array Aliasing — Two Variables, One Array

When you assign one array variable to another, both point to the same array in memory. This is aliasing. Changing one changes the other.

SURPRISING BEHAVIOR
int[] original = {1, 2, 3};
int[] copy = original;   // NOT a copy — same array
copy[0] = 99;
System.out.println(original[0]);  // prints 99
ACTUAL COPY
int[] original = {1, 2, 3};
int[] copy = new int[original.length];
for (int i = 0; i < original.length; i++)
{
    copy[i] = original[i];
}
copy[0] = 99;
System.out.println(original[0]);  // prints 1
Exam pattern: The MCQ gives you code like int[] b = a; then modifies b and asks for the value of a[0]. If you think b is an independent copy, you get it wrong. Arrays are objects — assignment copies the reference, not the data.

Mistake #6

Forgetting That New Object Arrays Default to null

When you create an array of objects (Strings, custom objects), every slot starts as null — not an empty String, not a default object. Calling a method on null throws NullPointerException.

WRONG
String[] words = new String[3];
System.out.println(words[0].length());
// NullPointerException — words[0] is null
CORRECT
String[] words = new String[3];
words[0] = "hello";
words[1] = "world";
words[2] = "test";
System.out.println(words[0].length());  // prints 5
Quick check: Primitive arrays (int[], double[]) default to 0 or 0.0. boolean[] defaults to false. Object arrays (String[], custom class arrays) default to null. The exam tests all three.

Mistake #7

Starting max/min at 0 Instead of the First Element

If you initialize max to 0 and all values in the array are negative, your “maximum” will be 0 — a value that is not even in the array.

WRONG
int[] vals = {-5, -2, -8, -1};
int max = 0;  // WRONG starting value
for (int i = 0; i < vals.length; i++)
{
    if (vals[i] > max)
    {
        max = vals[i];
    }
}
System.out.println(max);  // prints 0, not -1
CORRECT
int[] vals = {-5, -2, -8, -1};
int max = vals[0];  // start with actual first element
for (int i = 1; i < vals.length; i++)
{
    if (vals[i] > max)
    {
        max = vals[i];
    }
}
System.out.println(max);  // prints -1
Exam pattern: The MCQ gives you an array of all-negative or all-positive values and a find-max or find-min method that initializes to 0. You are asked what value is returned. The trick only works if you recognize the faulty initialization.

Mistake #8

Wrong Index Math in 2D Arrays

In a 2D array, arr.length gives the number of rows. arr[0].length gives the number of columns. Swapping these in a nested loop accesses out-of-bounds indices when the grid is not square.

WRONG
int[][] grid = new int[3][5];  // 3 rows, 5 columns
for (int r = 0; r < grid[0].length; r++)   // 5 — wrong for rows
{
    for (int c = 0; c < grid.length; c++)  // 3 — wrong for cols
    {
        grid[r][c] = r + c;
        // crashes when r=3 (only 0,1,2 are valid rows)
    }
}
CORRECT
int[][] grid = new int[3][5];  // 3 rows, 5 columns
for (int r = 0; r < grid.length; r++)       // 3 rows
{
    for (int c = 0; c < grid[0].length; c++) // 5 columns
    {
        grid[r][c] = r + c;
    }
}
Memory trick: grid.length = rows (how many sub-arrays). grid[0].length = columns (how long each sub-array is). Outer loop = rows = grid.length. Inner loop = columns = grid[0].length. Write it on your scratch paper before coding any 2D array problem.

Quick Reference: All 8 Mistakes

# Mistake What Happens Fix
1 <= in loop bound ArrayIndexOutOfBoundsException Use <
2 .length vs .size() Compile error Array = .length, ArrayList = .size()
3 == for Strings False match Use .equals()
4 Enhanced for modification Array unchanged Use standard for loop
5 Aliasing (b = a) Shared mutation Loop-copy into new array
6 Object array null default NullPointerException Initialize each element
7 max/min starts at 0 Wrong result Start at arr[0]
8 Swapped row/col bounds ArrayIndexOutOfBoundsException grid.length=rows, grid[0].length=cols

Ready to Eliminate These Mistakes?

54.5% of my AP CSA students score 5s. Let me help you join them.

4-Week Cram Kit — $29.99 Book Tutoring

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]