ARRAY.SPEC REV. 01 — JAVA

Arrays, laid out
index by index.

A small interactive reference for how Java arrays actually behave — declare it, walk it, search it, sort it, and go two-dimensional — built by working through it, hands-on.

Sheet 01 — Declare & Initialize

Build the block

An array is one contiguous, fixed-length block of same-typed slots. Type your own values below and watch the block get allocated.

int[] arr = new int[]{ ... };

      
Sheet 02 — Traverse

Walk every index

A for-loop visits index 0 through length−1 in order. Watch the pointer move and the running sum update.

Current index—
Running sum0
for (int i = 0; i < arr.length; i++) {
    sum += arr[i];
}
Press "Run traversal" to step through the array.
Sheet 03 — Linear Search

Find a value

No shortcuts — check each cell left to right until the target turns up, or the array runs out.

for (int i = 0; i < arr.length; i++) {
    if (arr[i] == target) return i;
}
return -1; // not found
Enter a target and press Search.
Sheet 04 — Bubble Sort

Order the block

Repeatedly compare neighbors and swap out-of-order pairs. Not the fastest sort — but the clearest one to watch.

Comparisons0
Swaps0
Pass—
for (int i = 0; i < n-1; i++)
  for (int j = 0; j < n-i-1; j++)
    if (arr[j] > arr[j+1]) {
        int tmp = arr[j];
        arr[j] = arr[j+1];
        arr[j+1] = tmp;
    }
Press "Run sort" to watch bubble sort work.
Sheet 05 — Two Dimensions

An array of arrays

arr2d[row][col] — a grid where each row is itself a full array. Click a cell to see its address.

int[][] grid = {
  {1, 2, 3, 4},
  {5, 6, 7, 8},
  {9, 10, 11, 12}
};
Click any cell in the grid to inspect it.