AP Computer Science A Reference Sheet
AP Computer Science A Reference Sheet
Complete Java Quick Reference for the 2025-2026 AP CSA Exam
📥 Want a Print-Ready PDF Bundle?
Get the premium bundle: 2-page condensed cheat sheet, FRQ scoring patterns, 10 code templates, 15 practice questions with answers, and exam day strategy guide.
Get PDF Bundle — $2.99String Methods
| Method | Returns | Example |
|---|---|---|
length() |
int |
"Hello".length() → 5 |
substring(start, end) |
String |
"Hello".substring(1, 4) → "ell" |
substring(start) |
String |
"Hello".substring(2) → "llo" |
indexOf(str) |
int |
"Hello".indexOf("l") → 2 |
equals(str) |
boolean |
"Hi".equals("hi") → false |
compareTo(str) |
int |
"A".compareTo("B") → negative |
charAt(index) |
char |
"Hello".charAt(0) → 'H' |
substring(start, end) includes start but excludes end.
Math Methods
| Method | Returns | Example |
|---|---|---|
Math.abs(x) |
int/double |
Math.abs(-5) → 5 |
Math.pow(base, exp) |
double |
Math.pow(2, 3) → 8.0 |
Math.sqrt(x) |
double |
Math.sqrt(16) → 4.0 |
Math.random() |
double | Returns 0.0 ≤ x < 1.0 |
(int)(Math.random() * range) + minExample: Random 1-6 (dice roll):
(int)(Math.random() * 6) + 1
ArrayList Methods
| Method | Returns | Description |
|---|---|---|
size() |
int | Number of elements |
get(index) |
E | Element at index |
set(index, value) |
E | Replace element, returns old value |
add(value) |
boolean | Add to end |
add(index, value) |
void | Insert at index, shifts others right |
remove(index) |
E | Remove at index, shifts others left |
Arrays vs ArrayList
| Operation | Array | ArrayList |
|---|---|---|
| Declare | int[] arr = new int[5]; |
ArrayList |
| Size | arr.length |
list.size() |
| Access | arr[i] |
list.get(i) |
| Modify | arr[i] = value; |
list.set(i, value); |
| Add element | N/A (fixed size) | list.add(value); |
2D Array Basics
| Operation | Code |
|---|---|
| Declare | int[][] grid = new int[rows][cols]; |
| Number of rows | grid.length |
| Number of columns | grid[0].length |
| Access element | grid[row][col] |
| Get entire row |
grid[row] (returns 1D array) |
2D Array Traversal
Operators
| Type | Operators |
|---|---|
| Arithmetic |
+ - * / % (mod = remainder) |
| Comparison |
== != < > <= >=
|
| Logical |
&& (and) || (or) ! (not) |
| Assignment |
= += -= *= /= %=
|
| Increment/Decrement |
x++ ++x x-- --x
|
Boolean Operators (Truth Table)
| A | B | A && B | A || B | !A |
|---|---|---|---|---|
true |
true |
true |
true |
false |
true |
false |
false |
true |
false |
false |
true |
false |
true |
true |
false |
false |
false |
false |
true |
&&) requires BOTH true. OR (||) requires at least ONE true.
compareTo() Return Values
| Expression | Returns | Meaning |
|---|---|---|
a.compareTo(b) |
negative (e.g., -1) | a comes BEFORE b alphabetically |
a.compareTo(b) |
0 | a EQUALS b |
a.compareTo(b) |
positive (e.g., 1) | a comes AFTER b alphabetically |
"Apple".compareTo("Banana") → negative (A comes before B)
Wrapper Classes (Autoboxing)
| Primitive | Wrapper | Why You Need It |
|---|---|---|
int |
Integer |
ArrayList |
double |
Double |
Autoboxing: Integer x = 5; (auto-converts) |
boolean |
Boolean |
Unboxing: int y = x; (auto-converts back) |
Loop Syntax
| Type | Syntax |
|---|---|
| for loop | for (int i = 0; i < n; i++) { } |
| while loop | while (condition) { } |
| for-each loop | for (Type item : collection) { } |
Selection Statements
| Type | Syntax |
|---|---|
| if | if (condition) { } |
| if-else | if (condition) { } else { } |
| if-else if | if (c1) { } else if (c2) { } else { } |
Class Structure (FRQ 2)
Common Traps (Watch Out!)
| Trap | Problem | Fix |
|---|---|---|
= vs ==
|
if (x = 5) assigns, not compares |
Use == for comparison |
| Integer division |
5/2 = 2, not 2.5 |
Cast: (double)5/2
|
String ==
|
Compares references, not content | Use .equals()
|
| Off-by-one |
< vs <=, wrong start index |
Trace with examples |
| Null pointer | Calling method on null | Check != null first |
; after if/while |
if (x > 0); { } — empty body! |
Remove the semicolon |
| ArrayList forward delete | Skips elements when removing | Loop backward |
Essential Code Patterns
Accumulator (Sum)
Find Maximum
ArrayList Removal (Loop Backward!)
Linear Search
📚 Ready to Ace the AP CSA Exam?
Get the complete Premium PDF Bundle with FRQ scoring patterns, 10 code templates, 15 practice questions, and exam day strategy.
Download PDF Bundle — $2.99© 2025 apcsexamprep.com — Good luck on your exam!
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.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
tanner@apcsexamprep.com
Courses
AP CSA, CSP, & Cybersecurity
Response Time
Within 24 hours
Prefer email? Reach me directly at tanner@apcsexamprep.com