01
Overview

Pulling specific fields from a list of objects.

When you have a list of full objects but only need one piece of information from each — sometimes only from the ones that qualify — accumulation with filtered extraction is the pattern.

An ArrayList of objects often carries more information than any single question needs. You may be holding ArrayList<Student> but the caller only wants the names of students who passed.

The combined pattern has two moves: filter (decide which objects qualify) and extract (pull one field from each qualifier into a new collection). The result is a fresh ArrayList whose element type is usually different from the source.

This pattern appears in nearly every AP CSA class-design FRQ that involves a list of objects — it's the natural way to summarize a collection.

02
Core Concept

Filter, then extract, then add.

A single accumulator list collects results across the traversal.

The template

public ArrayList<ReturnType> methodName(ArrayList<SourceType> source) {
    ArrayList<ReturnType> result = new ArrayList<ReturnType>();
    for (SourceType item : source) {
        if (/* filter condition on item */) {
            result.add(item.getSomeField());
        }
    }
    return result;
}

Three things change per problem: the source type, the return type, and the filter condition. The skeleton stays identical.

Concrete example

Assume a Student class with getName() and getGpa(). Return the names of students whose GPA is at least 3.0:

public ArrayList<String> namesOfPassingStudents(ArrayList<Student> students) {
    ArrayList<String> names = new ArrayList<String>();
    for (Student s : students) {
        if (s.getGpa() >= 3.0) {
            names.add(s.getName());
        }
    }
    return names;
}

Why enhanced for works here

Because we're reading from the source and writing to a different list, there's no modification of the source. The enhanced-for loop is clean and safe.

Type alignment

The result list's element type must match what getSomeField() returns. If getName() returns String, the result must be ArrayList<String> — never the original object type.

What if no objects qualify?

The loop runs but never adds. The method returns an empty ArrayList — not null. This is the expected AP CSA behavior.

03
Key Vocabulary

Terms used in object-list problems.

Used in FRQ rubrics for class-collection questions.

Vocabulary
  • Accumulator list — the new ArrayList that collects results.
  • Source list — the input ArrayList of objects being traversed.
  • Filter condition — the boolean expression that decides which objects qualify.
  • Field extraction — calling an accessor to pull one piece of data from an object.
  • Element type — the generic parameter in ArrayList<E>.
  • Accessor — a getXxx method on the source object.
04
AP Exam Focus

How filtered extraction is tested.

Return-type matching and accessor calls are the most-graded items.

Exam Focus

What FRQ graders check:

  • Exact return type. ArrayList<String> for names, ArrayList<Integer> for ints — not ArrayList<Student>.
  • Use of given accessor methods. Don't invent new ones; use the signatures the prompt provides.
  • Correct filter direction. "At least" includes the boundary; "more than" excludes it.
  • Empty-list handling. Return an empty ArrayList if nothing qualifies — never null.

MCQs often show the extraction code and ask "what's in the result list?" — trace by walking the source one object at a time.

05
Worked Example

Extract IDs of expensive books.

A standard filtered-extraction problem from a class spec.

Worked Example AP-style reasoning

Setup. A Book class has getId() returning int and getPrice() returning double. Given ArrayList<Book> library, return an ArrayList<Integer> of IDs for books that cost more than $50.

Step 1. Identify the return type: ArrayList<Integer> because IDs are int (autoboxed to Integer).

Step 2. Write the template with the correct types.

Step 3. Filter with getPrice() > 50; extract with getId().

public ArrayList<Integer> expensiveBookIds(ArrayList<Book> library) {
    ArrayList<Integer> ids = new ArrayList<Integer>();
    for (Book b : library) {
        if (b.getPrice() > 50) {
            ids.add(b.getId());
        }
    }
    return ids;
}

Trace. If the library has four books with prices 30, 60, 45, 80 and IDs 1, 2, 3, 4 respectively, the result is [2, 4].

Why this matters. Notice how the result element type differs from the source type. This is the most common student confusion — they accidentally write ArrayList<Book> as the return type and add whole books instead of IDs.

06
Common Mistakes

Errors that lose easy FRQ points.

Most come from wrong types or missing accessors.

Watch Out
  • Wrong generic type on the result. Adding String to an ArrayList<Student> won't compile.
  • Adding the whole object instead of the field. result.add(s) when you meant result.add(s.getName()).
  • Direct field access. s.name won't compile when fields are private; use s.getName().
  • Inverted filter. Returning passing students vs failing students — read the prompt twice.
  • Returning null on empty. Return the empty list instead.
  • Using ArrayList<int>. Won't compile; use ArrayList<Integer>.
07
Reference Table

Filtered extraction at a glance.

A checklist for every problem of this shape.

Filtered Extraction Reference

AP Quick Reference
Step Action AP Exam Tip
1 Create empty result list Element type matches what you'll add.
2 Loop over source objects Enhanced for is clean — no mutation of source.
3 Apply filter condition Read the prompt for exact boundary.
4 Extract field via accessor Use the exact method name from the spec.
5 Add to result list Add the field's value, not the object.
6 Return result Never null — empty list if nothing qualifies.
08
Practice Tip

How to internalize filtered extraction.

One template, many variants — drill until it's reflex.

Practice Strategy

Use the three practice tools below this lesson in order:

  • MCQ Practice — for each problem, write down the source type, the return type, the filter, and the extractor before tracing. Most wrong answers fail one of those four checks.
  • Java Lab — implement filtered extraction for several class specs: names of passing students, IDs of expensive books, titles of long songs. Re-use the same template every time.
  • FRQ Practice — write the result-list declaration first with the correct generic type, then the loop, then the filter, then the add. Match the prompt's accessor names exactly.

If you can declare the result list's type correctly within five seconds of reading the prompt, you've mastered this pattern.

09
Section · 09

Practice — attempt these now.

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

Topic Quiz 40 min 40 marks Pending

AP CSA Topic Practice: Accumulation and Filtered Field Extraction

AP-style topic practice assessment

Start
FRQ Practice 30 min 18 marks Pending

AP CSA Unit 06 Topic 01 Accumulation and Filtered Field Extraction FRQ Practice

AP-style topic practice assessment

Start