2026 AP CSA Java Quick Reference — Methods You Must Memorize

What You Need to Know

On the AP CSA exam, you’re only guaranteed the built-in methods that appear on the AP CSA Java Quick Reference (plus whatever a problem explicitly tells you). This means you must be able to:

  • Recognize method signatures (return type + parameters)
  • Predict exact return values (especially edge cases)
  • Handle String indexing and ArrayList shifting without guessing
  • Use Math.random() correctly to generate ranges

Critical rule: You can assume these methods exist and behave exactly as Java specifies. If you use other library methods (like String.toUpperCase()), you can’t assume they exist unless the question provides them.

The “must-memorize” classes

From the Quick Reference, you should memorize methods for:

  • String
  • Math
  • Integer and Double (wrapper classes)
  • ArrayList

Also memorize these non-method essentials:

  • Array has a public field length (not a method)
  • Indices are 0-based for Strings, arrays, and ArrayLists

Step-by-Step Breakdown

This topic is mostly recall + precise application. Here are the repeatable “micro-procedures” you’ll use constantly.

1) Safely use substring
  1. Identify indices as 0-based.
  2. If using substring(from, to), remember it returns characters at indices:
    from,from+1,,to1from, from+1, \dots, to-1
    (the to index is excluded).
  3. If using substring(from), it returns from from through the end.
  4. Watch for index errors (the exam typically avoids invalid indices unless it’s testing you).

Mini-check: str.substring(a, b) has length bab-a.

2) Use indexOf like a pro
  1. Decide what you’re searching for: a String pattern.
  2. Use indexOf(str) to find the first occurrence.
  3. Use indexOf(str, fromIndex) to find the first occurrence starting at fromIndex.
  4. If the result is 1-1, the pattern is not found.

Common pattern: find the second occurrence

  • Find first index i = s.indexOf(target)
  • Find next: j = s.indexOf(target, i + 1)
3) Interpret compareTo correctly
  1. s1.compareTo(s2) compares lexicographically (dictionary-like).
  2. Only the sign matters:
    • negative → s1 comes before s2
    • 00 → equal
    • positive → s1 comes after s2
  3. Don’t assume the return is exactly 1-1 or 11.
4) Generate random integers with Math.random()
  1. Know the range:
    Math.random()[0.0,1.0)\text{Math.random()} \in [0.0, 1.0)
  2. To get an integer in [0,n)[0, n):
    • multiply by n, cast to int
int r = (int)(Math.random() * n); // 0..n-1
  1. To get an integer in [a,b][a, b] (inclusive):
    • size is ba+1b-a+1
int r = a + (int)(Math.random() * (b - a + 1));
5) Predict ArrayList shifting (add/remove)
  1. add(index, obj) inserts and shifts old elements at index...end right.
  2. remove(index) deletes and shifts elements after it left.
  3. In loops, shifting can cause you to skip elements or go out of bounds.

Key Formulas, Rules & Facts

String (memorize these signatures + behaviors)
Method signatureWhat it doesMust-know notes
int length()number of charactersindices valid: 00 to length1length-1
String substring(int from, int to)slice of stringincludes from, excludes to ([from,to)[from,to))
String substring(int from)slice to endincludes from through last char
int indexOf(String str)first match indexreturns 1-1 if not found
int indexOf(String str, int fromIndex)first match at/after indexfromIndex is a position to start searching
int compareTo(String other)lexicographic comparenegative / 00 / positive; not just 1,0,1-1,0,1
boolean equals(Object other)content equalityuse for Strings, not ==

String indexing facts

  • First char is index 00.
  • Last char index is length()1length()-1.
Math (you must know return types + ranges)
Method signatureWhat it doesNotes
static int abs(int x)absolute valuereturns int
static double abs(double x)absolute valuereturns double
static double pow(double base, double exponent)exponentiationreturns double even for integer-looking inputs
static double sqrt(double x)square rootreturns double
static double random()uniform random double[0.0,1.0)\in [0.0, 1.0)
Wrapper classes: Integer and Double

These show up when code stores primitives in collections (like ArrayList<Integer>).

ClassMethod / constructorWhat it doesNotes
IntegerInteger(int value)constructs an Integer objectoften replaced by autoboxing, but still tested conceptually
Integerint intValue()unwrap to intunboxing sometimes implicit
Integerstatic int parseInt(String s)converts String to primitive intassume valid numeric strings unless stated
DoubleDouble(double value)constructs a Double objectconceptually like Integer
Doubledouble doubleValue()unwrap to double
Doublestatic double parseDouble(String s)converts String to primitive doubleassume valid numeric strings unless stated
ArrayList
Method signatureWhat it doesNotes
int size()number of elementslast index is size()1size()-1
boolean add(E obj)append to endreturns true (typically ignored)
void add(int index, E obj)insert at indexshifts right (existing elements move up)
E get(int index)element at indexdoes not remove
E set(int index, E obj)replace at indexreturns old element
E remove(int index)remove at indexshifts left; returns removed element
Arrays (not methods, but always tested)
  • arr.length is a field, not a method.
    • Correct: arr.length
    • Wrong: arr.length()

Examples & Applications

Example 1: substring boundaries
String s = "computer";
System.out.println(s.substring(1, 4));
System.out.println(s.substring(3));

Key insight: substring(1,4) is indices 1,2,31,2,3.

  • Output:
    • omp
    • puter
Example 2: Finding multiple occurrences with indexOf
String s = "bananas";
int first = s.indexOf("an");
int second = s.indexOf("an", first + 1);
System.out.println(first + "," + second);

Key insight: searching again must start after the previous match.

  • first is 11, second is 33 → prints 1,3
Example 3: compareTo sign (not exact value)
String a = "ape";
String b = "apple";
System.out.println(a.compareTo(b) < 0);
System.out.println(b.compareTo(a) > 0);
System.out.println(a.compareTo("ape") == 0);

Key insight: Only check < 0, > 0, or == 0.

  • Outputs: true, true, true
Example 4: ArrayList shifting trap
ArrayList<Integer> nums = new ArrayList<>();
nums.add(10);
nums.add(20);
nums.add(30);
nums.add(1, 99);   // insert at index 1
nums.remove(2);    // remove element currently at index 2
System.out.println(nums);

Step through:

  • After insert: [10, 99, 20, 30]
  • After remove index 22: removes 20[10, 99, 30]
Example 5: Random integer in an inclusive range

Generate 55 through 99 inclusive:

int r = 5 + (int)(Math.random() * (9 - 5 + 1));

Key insight: range size is 95+1=59-5+1 = 5 values.


Common Mistakes & Traps

  1. Using == for Strings

    • Wrong: if (s1 == s2)
    • Why wrong: compares references, not content.
    • Fix: s1.equals(s2).
  2. Forgetting substring excludes the end index

    • Wrong thought: “substring(2,5) gives 4 chars.”
    • Reality: length is 52=35-2 = 3.
    • Fix: remember [from,to)[from,to).
  3. Assuming compareTo returns only 1,0,1-1,0,1

    • Wrong: if (s1.compareTo(s2) == -1)
    • Why wrong: any negative number means “before.”
    • Fix: use < 0, == 0, > 0.
  4. Not handling indexOf returning 1-1

    • Wrong: using the result as an index without checking.
    • Why wrong: -1 is not a valid index.
    • Fix: int i = s.indexOf(t); if (i != -1) { ... }.
  5. Calling arr.length() like a method

    • Wrong: arr.length()
    • Why wrong: arrays use a field.
    • Fix: arr.length.
  6. Off-by-one with last valid index

    • Wrong loop: for (int i = 0; i <= list.size(); i++)
    • Why wrong: last index is size()1size()-1.
    • Fix: i < list.size().
  7. Breaking loops by modifying an ArrayList while iterating forward

    • What happens: remove(i) shifts elements left, so the next element moves into index i and you skip it.
    • Fix options:
      • iterate backward (for (int i = size-1; i >= 0; i--)), or
      • adjust index carefully.
  8. Wrong random range due to missing cast parentheses

    • Wrong:
      java int r = (int)Math.random() * n; // always 0
    • Why wrong: (int)Math.random() is always 00.
    • Fix:
      java int r = (int)(Math.random() * n);

Memory Aids & Quick Tricks

Trick / mnemonicHelps you rememberWhen to use
Substring is “start inclusive, end exclusive” [from,to)[from,to)substring(from,to) excludes toAny substring boundary question
“IndexOf: -1 means ‘nope’”not-found value is 1-1Before using indexOf result as an index
CompareTo = sign checkuse <0, ==0, >0 onlyConditionals with lexicographic order
Random: multiply then castcasting too early breaks itAny random int generation
ArrayList add/remove SHIFTinsert shifts right, remove shifts leftTracing list mutations
Last valid index = size/length minus 1avoid off-by-oneLoops and boundary checks

Quick Review Checklist

  • You can list all Quick Reference methods for String, Math, Integer, Double, ArrayList from memory.
  • You remember String/array/list indices start at 00.
  • You know substring(from,to) is [from,to)[from,to) and has length tofromto-from.
  • You know indexOf(...) returns 1-1 when not found.
  • You use equals (not ==) for String content.
  • You interpret compareTo by its sign, not its exact value.
  • You know Math.random() returns [0.0,1.0)[0.0,1.0).
  • You can generate a random integer in [0,n)[0,n) and [a,b][a,b].
  • You can predict how ArrayList.add(index, ...) and remove(index) shift elements.

You’ve got this—if you can trace these methods accurately, you’re covering a huge chunk of AP CSA points.