01
Overview

Parallel arrays with conditional construction.

Two aligned arrays drive a third — built only from rows that satisfy a condition.

Parallel arrays share an index: index i in names[] and index i in scores[] refer to the same logical entity. Conditional construction builds a new array (or pair of arrays) containing only the entries that meet a test.

Because the result list's size isn't known up front, you either count first to allocate, or use an ArrayList and convert.

On the AP exam, parallel arrays appear in pre-object-oriented problems and as a stepping stone toward ArrayLists of objects.

02
Core Concept

Maintain alignment; build the result with a running index.

Two passes: count, then build.

Two-pass build (fixed-size result)

public String[] passingNames(String[] names, int[] scores, int threshold) {
    int count = 0;
    for (int s : scores) if (s >= threshold) count++;

    String[] result = new String[count];
    int j = 0;
    for (int i = 0; i < names.length; i++) {
        if (scores[i] >= threshold) {
            result[j] = names[i];
            j++;
        }
    }
    return result;
}

First pass counts; second pass copies. The variable j tracks the next free position in result.

Alignment is sacred

Whatever happens to one array must happen to the other at the same index. Sorting one independently breaks the relationship.

03
Key Vocabulary

Parallel-array vocabulary.

Used in indexed-record problems.

Vocabulary
  • Parallel arrays — aligned by index.
  • Logical record — combined data at a shared index.
  • Conditional build — constructing result only from qualifying entries.
  • Running index — counter tracking the next free position in the result.
  • Two-pass build — count then copy.
04
AP Exam Focus

How parallel arrays are tested.

Alignment and result-size dominate.

Exam Focus
  • Alignment. Never sort or modify one without the other.
  • Result size. Must equal the count of matches.
  • Running index. Increment only when adding to result.
  • Source untouched. Conditional build is non-destructive.
05
Worked Example

Build passing names.

Two passes; trace each.

Worked Example AP-style reasoning

Input: names = ["Alex", "Ben", "Cara", "Dax"], scores = [85, 50, 72, 40], threshold 60.

Pass 1 — count: 85, 72 qualify → count = 2.

Pass 2 — build:

  • i=0: 85 ≥ 60 → result[0] = "Alex"; j=1.
  • i=1: 50 < 60 → skip.
  • i=2: 72 ≥ 60 → result[1] = "Cara"; j=2.
  • i=3: 40 < 60 → skip.

Result: ["Alex", "Cara"].

06
Common Mistakes

Parallel-array pitfalls.

Most break alignment or miscount.

Watch Out
  • Allocating wrong-size result. Must equal count from pass 1.
  • Running j always. Increment only when adding.
  • Using i instead of j in result. Leaves gaps or overwrites.
  • Modifying source arrays. Breaks alignment.
07
Reference Table

Parallel-array build template.

Two passes; running index.

Parallel Build Reference

AP Quick Reference
StepActionVariable
1Count matchescount
2Allocate resultsize = count
3Copy matchesj (running index)
4Return result
08
Practice Tip

How to master parallel arrays.

Count first; copy second.

Practice Strategy
  • MCQ Practice — verify j increments only on match.
  • Java Lab — implement passingNames, expensiveItems with parallel arrays. Verify alignment.
  • FRQ Practice — write the two-pass count-then-build pattern; never sort one array independently.
09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

FRQ Practice 30 min 18 marks Pending

AP CSA Unit 07 Topic 13 Parallel Arrays and Conditional Build FRQ Practice

AP-style topic practice assessment

Start