1/46
Lowk just used claude 4.5 sonnet, the goat.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
For each [item] in [list/array]
for (Type item : list) — use when you don't need the index
For each index from 0 to n
for (int i = 0; i < n; i++) — use when index matters or you need to modify elements
Traverse the array/list
for (int i = 0; i < arr.length; i++) OR for (Type x : arr) — "traverse" just means loop through every element
While [condition] is true
while (condition) { … } — keep looping until the condition becomes false
Repeat for each hour / each element (inclusive range)
for (int i = start; i <= end; i++) — inclusive means use <= not <
Accumulate / keep a running total
int total = 0; total += value; — always initialize before the loop
Count the number of [items] that…
int count = 0; if (condition) count++; — increment inside the loop when condition is met
Find the minimum / maximum
int best = list.get(0); for (int x : list) if (x > best) best = x; — initialize with first element, not 0
If at least one of the following is true
if (condA || condB) — || is OR, true if either side is true
If all of the following are true
if (condA && condB) — && is AND, both must be true
If [x] is between [a] and [b], inclusive
if (x >= a && x <= b) — inclusive means include the endpoints
If [x] is between [a] and [b], exclusive
if (x > a && x < b) — exclusive means exclude the endpoints
If none of / not
if (!condition) — ! flips true to false and vice versa
Otherwise / in all other cases
else { … } — runs when none of the if/else if conditions matched
The larger/smaller of two values
Math.max(a, b) / Math.min(a, b) — no need to write your own if/else
Bonus / additional amount if condition
if (condition) total += bonus; — add the bonus inside a conditional, after the base amount
The number of elements in the array
arr.length — no parentheses, length is a field not a method
The number of elements in the ArrayList
list.size() — for ArrayLists use .size() with parentheses
Get the element at index i
arr[i] for arrays, list.get(i) for ArrayLists
Set / update the element at index i
arr[i] = value; for arrays, list.set(i, value); for ArrayLists
Add an element to the ArrayList
list.add(value); adds to end — list.add(i, value); inserts at index
Remove an element from the ArrayList
list.remove(i); — removes by index, remaining elements shift left
Check if the ArrayList contains a value
list.contains(value) — returns true/false, works on objects not primitives
Create a new ArrayList
ArrayList
The last index / last element
arr.length - 1 for arrays, list.size() - 1 for ArrayLists — always subtract 1
2D array — row i, column j
grid[i][j] — first bracket is row, second is column
Number of rows/columns in a 2D array
grid.length for rows, grid[0].length for columns
The length of the string
str.length() — strings use .length() with parentheses, unlike arrays
Get the character at index i
str.charAt(i) — returns a char, index starts at 0
Get a portion of the string
str.substring(start, end) — includes start, excludes end
Check if string contains a value
str.contains("x") OR str.indexOf("x") >= 0 — indexOf returns -1 if not found
Compare two strings for equality
str1.equals(str2) — NEVER use == for Strings, it checks reference not content
Convert to upper/lowercase
str.toUpperCase() / str.toLowerCase() — returns a new String, Strings are immutable
The index where [x] first appears
str.indexOf("x") — returns -1 if not found, always check before using
Write a class with instance variables
public class Name { private Type var; } — instance variables should almost always be private
Write a constructor
public ClassName(Type param) { this.var = param; } — constructor name must match class name exactly
Write a getter method
public Type getVar() { return var; } — getters provide read access to private fields
Write a setter / update method
public void setVar(Type val) { this.var = val; } — void means no return value
Call a method on an object
object.methodName(args) — you need a reference to the object
Use a helper method provided
Just call it — don't reimplement it. int result = helperMethod(arg);
Assume [method] works correctly
Call it and trust the return value — never rewrite it
Returns the [value] / return the result
return value; — every non-void method must have a return statement
Returns true if [condition], false otherwise
return condition; — you can return a boolean expression directly
Returns the total / sum
int total = 0; // loop adding to total; return total; — accumulate then return after loop
Returns the number of [items] that…
int count = 0; // loop counting; return count; — same pattern, count in loop, return after
void method — does not return a value
public void methodName() { } — void methods perform an action but return nothing
Returns a new list/collection
ArrayList