Java Arrays and ArrayLists Cheat Sheet
The core ideas of Java Arrays and ArrayLists distilled into a single, scannable reference — perfect for review or quick lookup.
Quick Reference
Array Declaration and Initialization
Arrays are fixed-size collections declared with a type and size. Elements are initialized to default values (0 for int, null for objects, false for boolean).
Array Indexing
Array elements are accessed by zero-based integer index. The valid range is 0 to array.length - 1. Accessing an out-of-bounds index throws ArrayIndexOutOfBoundsException.
Array Traversal
Visiting every element of an array using a loop. Standard for loops use an index variable; enhanced for-each loops iterate directly over elements.
ArrayList
A resizable collection from java.util that stores objects. Provides methods like add(), get(), set(), remove(), and size(). Requires import java.util.ArrayList.
Autoboxing and Unboxing
Automatic conversion between primitive types and their wrapper classes (int <-> Integer, double <-> Double) when using ArrayLists, which cannot store primitives directly.
2D Arrays
Arrays of arrays used to represent tabular or grid data. Accessed with two indices: row and column. Declared as type[][] name = new type[rows][cols].
Linear Search
A sequential search algorithm that checks each element of an array one by one until the target is found or the end is reached. Time complexity: O(n).
Array vs ArrayList
Arrays are fixed-size and can hold primitives or objects. ArrayLists are resizable but can only hold objects. Arrays use [] syntax; ArrayLists use method calls.
Enhanced For Loop (for-each)
A simplified loop syntax that iterates over every element in an array or collection without using an index variable. Cannot modify the array or skip elements.
Key Terms at a Glance
Get study tips in your inbox
We'll send you evidence-based study strategies and new cheat sheets as they're published.
We'll notify you about updates. No spam, unsubscribe anytime.