2004 AP CSA FRQ 1: WordList - Complete Solution

2004 AP CSA FRQ 1: WordList

Topic: ArrayList & String Processing

Skills Tested: ArrayList traversal, String length checking, removing while iterating

Curriculum Alignment: Unit 4 (Data Collections) (2025-2026 AP CSA)

Points: 9 | Time Estimate: ~22 minutes

Part (a)

Write the numWordsOfLength method that returns the count of words with exactly len letters.

Try It First! Attempt to solve this part before viewing the solution. Use the concepts: ArrayList traversal.

Solution

public int numWordsOfLength(int len)
{
    int numWords = 0;
    for (int i = 0; i < myList.size(); i++)
    {
        String word = (String) myList.get(i);
        if (word.length() == len)
            numWords++;
    }
    return numWords;
}

Part (b)

Write the removeWordsOfLength method that removes all words with exactly len letters from the list.

Solution

public void removeWordsOfLength(int len)
{
    int i = 0;
    while (i < myList.size())
    {
        String word = (String) myList.get(i);
        if (word.length() == len)
            myList.remove(i);
        else
            i++;
    }
}

Key Concepts

Use a while loop (not for-each) when removing elements to avoid ConcurrentModificationException
Only increment index when NOT removing an element
Cast to String was required in 2004 (modern Java uses generics)

Common Mistakes to Avoid

Using for-each loop when removing elements causes ConcurrentModificationException
Incrementing index after removal causes skipped elements
Off-by-one errors in loop bounds
Forgetting to cast Object to String (2004 requirement)

Scoring Guidelines

Total Points: 9

Points are awarded for:

  • Correct loop structure and bounds
  • Proper method calls and return statements
  • Correct conditional logic
  • Handling edge cases appropriately

Partial credit is available for demonstrating understanding even with minor syntax errors.

Official College Board Resources

About the Author: Tanner Crow is a certified AP Computer Science teacher with 11+ years of experience helping students succeed on the AP CSA exam.

Last updated: January 2026

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]