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.
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
Common Mistakes to Avoid
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
Continue Studying
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