int, double, char, boolean …new, default value is nullIndices always start at 0 and go to length−1.
An array like int[] freq = new int[7] can tally how many times each face of a die appears — freq[face]++.
Java is always pass-by-value — but for arrays/objects, the "value" passed is the reference itself. So a method can modify the array's elements, but reassigning the parameter inside the method does not affect the caller's variable.
array[row][col]for loops (outer = rows, inner = columns)public static void main(String[] args) — args holds whatever was typed after the program name.
Arrays.sort()Arrays.toString()Arrays.binarySearch()Arrays.fill()ArrayList grows/shrinks dynamicallyArrayList is part of the Collections Framework (java.util)int → Integer)| Method | Purpose |
|---|---|
sort(arr) | sorts in ascending order |
toString(arr) | readable String like [1, 2, 3] |
binarySearch(arr, key) | index of key in a sorted array |
fill(arr, value) | sets every element to value |
equals(a1, a2) | true if same length & elements |
copyOf(arr, n) | new array of length n, copied from arr |
| Method | Purpose |
|---|---|
add(item) | appends to end |
add(i, item) | inserts at index i |
get(i) | element at index i |
set(i, item) | replaces element at index i |
remove(i) / remove(item) | removes by index / by value |
size() | current number of elements |
contains(item) | true if present |
indexOf(item) | first index of item, or -1 |
clear() | removes all elements |