---
title: "Column Index — AP Comp Sci A Definition & Exam Guide"
description: "The column index is the second number in arr[row][col], picking which column of a 2D array you access. It powers column traversals on AP CSA FRQ 4."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/column-index"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 4"
---

# Column Index — AP Comp Sci A Definition & Exam Guide

## Definition

In AP Computer Science A, the column index is the second index in 2D array notation arr[row][col]. It selects which element within a row you're accessing, runs from 0 to arr[0].length - 1, and is the loop variable you fix or vary when traversing a 2D array by column.

## What It Is

The column index is the second number in the bracket notation `arr[row][col]` you use to grab one element out of a [2D array](/ap-comp-sci-a/unit-4/2d-arrays/study-guide/5WDx6ZFeWhx2aVuiZI6R "fv-autolink"). Java stores a 2D array as an array of arrays (EK 4.11.A.1), so `arr[row]` first pulls out one entire row (which is itself a [1D array](/ap-comp-sci-a/key-terms/1d-array "fv-autolink")), and then `[col]` picks one element inside that row. The column index tells you how far across you are.

Like every [index](/ap-comp-sci-a/key-terms/index "fv-autolink") in Java, it starts at 0. For a rectangular 2D array, valid column indexes run from `0` to `arr[0].length - 1`. That expression trips people up, so read it slowly. `arr.length` is the number of rows, but `arr[0].length` is the length of row 0, which is the number of columns. Go past that boundary and you get an `ArrayIndexOutOfBoundsException`. Since a 2D array's size is fixed at creation, the range of valid column indexes never changes.

## Why It Matters

The column index lives in Topic 4.11 (2D Arrays) in [Unit 4](/ap-comp-sci-a/unit-4 "fv-autolink"): Data Collections, supporting learning objective 4.11.A, which asks you to develop code that represents related data using 2D array [objects](/ap-comp-sci-a/key-terms/object "fv-autolink"). You can't write a single line of 2D array code without getting row and column indexes right, and the AP exam knows it. Almost every Question 4 FRQ is a 2D array problem, and the most common errors graders see are swapped indexes (`arr[c][r]` instead of `arr[r][c]`) and off-by-one bounds. Mastering the column index also unlocks the classic traversal patterns the exam loves, like processing one specific column, sweeping column-major instead of row-major, or walking the diagonal where row index equals column index.

## Connections

### [Row index (Unit 4)](/ap-comp-sci-a/key-terms/row-index)

The [row index](/ap-comp-sci-a/key-terms/row-index "fv-autolink") is the column index's partner, the first bracket in arr[row][col]. Think of it like seats in a theater. The row index gets you to the right row, and the column index walks you to your seat. Swap them and you're sitting in the wrong place, or off the edge of the theater entirely.

### 1D arrays and array-of-arrays structure (Unit 4)

Because a 2D array is literally an array of arrays, arr[row] by itself is a valid 1D array. The column index is just a normal 1D array index applied to that row. Everything you learned about 1D indexing in Topic 4.1 (zero-based, length [bounds](/ap-comp-sci-a/key-terms/bounds "fv-autolink"), out-of-bounds exceptions) applies directly.

### Nested loop traversal (Unit 4)

Standard row-major [traversal](/ap-comp-sci-a/key-terms/traversal "fv-autolink") puts the row loop outside and the column index in the inner loop, so the column index resets to 0 for every new row. Flip the loops and the column index becomes the outer variable, giving you column-major order. The exam tests whether you can tell these apart just by reading which index the inner loop controls.

### [Latin square (Unit 4)](/ap-comp-sci-a/key-terms/latin-square)

Latin square problems (like a released FRQ scenario) make you check rows and columns for the same set of values. Verifying a column means fixing the column index and looping over the row index, the reverse of the usual pattern. It's a great test of whether you actually understand which index does what.

## On the AP Exam

Question 4 of the FRQ section is almost always a 2D array problem, and column index control is usually where the points live. The 2018 FRQ Q4 literally said "Precondition: c is a valid column index" and asked you to return all elements of column c, which requires fixing the column index and looping over rows. The 2019 LightBoard and 2022 Data FRQs also required clean row/column index handling. In multiple choice, expect code-reading stems like "what does this method do?" where the answer hinges on the indexes. A loop summing arr[r][index] across all r is summing one column. A loop adding arr[i][i] is summing the main diagonal, where row and column index are equal. A condition like r + c == 2 targets an anti-diagonal. You need to translate index patterns into plain-English behavior, fast.

## column index vs Row index

In arr[row][col], the row index comes first and the column index comes second, always. The confusion gets worse with bounds. The number of rows is arr.length, but the number of columns is arr[0].length, the length of one row. So the column index is bounded by arr[0].length, not arr.length. A loop like for (int c = 0; c < arr.length; c++) used as a column loop is a classic FRQ point-loser on non-square arrays. A quick memory hook is "RC Cola": Row, then Column.

## Key Takeaways

- The column index is the second index in arr[row][col] and selects which element you access within a row.
- Valid column indexes run from 0 to arr[0].length - 1, because arr[0].length gives the number of columns while arr.length gives the number of rows.
- A 2D array is an array of arrays, so the column index is just a regular 1D array index applied to the row arr[row].
- To traverse a single column, fix the column index and loop the row index from 0 to arr.length - 1, like the 2018 FRQ Q4 column-extraction problem.
- In code-reading questions, arr[i][i] means the diagonal (row index equals column index) and arr[r][index] with r looping means one fixed column.
- Using a column index outside its valid range throws an ArrayIndexOutOfBoundsException at runtime.

## FAQs

### What is the column index in a 2D array in Java?

It's the second index in the notation arr[row][col]. It specifies which element within a row you're accessing, starting at 0 and going up to arr[0].length - 1.

### Does the column index come first or second in Java 2D arrays?

Second, always. Java uses arr[row][col], so arr[2][5] means row 2, column 5. Writing arr[col][row] by mistake is one of the most common ways to lose points on FRQ 4.

### Is arr.length the number of columns?

No. arr.length is the number of rows. The number of columns is arr[0].length, the length of one row, because a 2D array is stored as an array of row arrays.

### How is a column index different from a row index?

The row index (first bracket) picks which row array you're in, and the column index (second bracket) picks the element inside that row. They have different bounds too: row index is limited by arr.length, column index by arr[0].length.

### How do I loop through one column of a 2D array?

Hold the column index constant and loop the row index: for (int r = 0; r < arr.length; r++) { use arr[r][c]; }. This exact pattern earned points on the 2018 AP CSA FRQ Q4, which asked for all elements of a given column.

## Related Study Guides

- [4.11 2D Arrays](/ap-comp-sci-a/unit-4/2d-arrays/study-guide/5WDx6ZFeWhx2aVuiZI6R)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/column-index#resource","name":"Column Index — AP Comp Sci A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/column-index","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/column-index#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:18.981Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/column-index#term","name":"column index","description":"In AP Computer Science A, the column index is the second index in 2D array notation arr[row][col]. It selects which element within a row you're accessing, runs from 0 to arr[0].length - 1, and is the loop variable you fix or vary when traversing a 2D array by column.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/column-index","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the column index in a 2D array in Java?","acceptedAnswer":{"@type":"Answer","text":"It's the second index in the notation arr[row][col]. It specifies which element within a row you're accessing, starting at 0 and going up to arr[0].length - 1."}},{"@type":"Question","name":"Does the column index come first or second in Java 2D arrays?","acceptedAnswer":{"@type":"Answer","text":"Second, always. Java uses arr[row][col], so arr[2][5] means row 2, column 5. Writing arr[col][row] by mistake is one of the most common ways to lose points on FRQ 4."}},{"@type":"Question","name":"Is arr.length the number of columns?","acceptedAnswer":{"@type":"Answer","text":"No. arr.length is the number of rows. The number of columns is arr[0].length, the length of one row, because a 2D array is stored as an array of row arrays."}},{"@type":"Question","name":"How is a column index different from a row index?","acceptedAnswer":{"@type":"Answer","text":"The row index (first bracket) picks which row array you're in, and the column index (second bracket) picks the element inside that row. They have different bounds too: row index is limited by arr.length, column index by arr[0].length."}},{"@type":"Question","name":"How do I loop through one column of a 2D array?","acceptedAnswer":{"@type":"Answer","text":"Hold the column index constant and loop the row index: for (int r = 0; r < arr.length; r++) { use arr[r][c]; }. This exact pattern earned points on the 2018 AP CSA FRQ Q4, which asked for all elements of a given column."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 4","item":"https://fiveable.me/ap-comp-sci-a/unit-4"},{"@type":"ListItem","position":4,"name":"column index"}]}]}
```
