
The ArrayList is one of the most frequently tested topics on the AP Computer Science A exam.
Students must understand how to add, remove, modify, filter, and search elements inside an ArrayList — often with loops and conditions combined.
This page gives you, exam-style FRQs to strengthen your ArrayList logic and exam performance.
Why Practice ArrayList FRQs?
ArrayList FRQs commonly test:
- Adding items
- Removing items
- Filtering elements
- Counting and searching
- Processing lists of objects
- In-place mutation of a list
- Iteration using for-loop or enhanced for-loop
- Avoiding ConcurrentModification issues
Mastering these patterns will significantly improve your FRQ score.
How to Use This Page
- Attempt each problem before viewing the solution
- Trace index movement on paper
- Pay attention to why
i--is required - Rewrite solutions from scratch
- Focus on logic, not memorization
This mirrors how FRQs are graded by the College Board.
FRQ 1 — Count Values Above a Threshold
Write countAbove(ArrayList<Integer> list, int limit)
that returns how many values in the list are strictly greater than
limit.
[10, 25, 30, 18], limit = 20 → 2
- Traverse the list
- Compare each value with
limit - Increment a counter
public int countAbove(ArrayList list, int limit) {
int count = 0;
for (int v : list) {
if (v > limit) {
count++;
}
}
return count;
}
- Using
>=instead of> - Returning the value instead of the count
FRQ 2 — Count Strings Containing a Letter
Write countContaining(ArrayList<String> list, String letter)
that returns how many strings contain letter.
[“cat”, “dog”, “car”], “a” → 2
- Loop through the list
- Use
contains() - Count matches
public int countContaining(ArrayList list, String letter) {
int count = 0;
for (String s : list) {
if (s.contains(letter)) {
count++;
}
}
return count;
}
- Using
==instead of.equals()for Strings - Ignoring case sensitivity
FRQ 3 — Find First Matching Object
Return the index of the first Student whose name matches
name. If not found, return -1.
[“Amit”, “Riya”, “John”], “Riya” → 1
- Traverse using indices
- Use
.equals()to compare names - Return index immediately
public int findStudent(ArrayList list, String name) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getName().equals(name)) {
return i;
}
}
return -1;
}
- Using
==for String comparison - Returning the object instead of the index
FRQ 4 — Remove All Negative Numbers
Remove all negative values from the list.
[5, -2, 7, -1] → [5, 7]
- Traverse using indices
- Remove negatives
- Decrement index after removal
public void removeNegatives(ArrayList list) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i) < 0) {
list.remove(i);
i--;
}
}
}
- Forgetting
i--after removal - Using enhanced for-loop while removing
FRQ 5 — Remove Short Strings
Remove all strings shorter than minLength.
["hi", "hello", "java"], minLength = 4 → ["hello", "java"]
- Check string length
- Remove if condition fails
- Adjust index
public void removeShortStrings(ArrayList list, int minLength) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).length() < minLength) {
list.remove(i);
i--;
}
}
}
- Skipping elements after removal
- Comparing Strings instead of lengths
FRQ 6 — Insert After Target Word
Insert toAdd immediately after every occurrence
of target.
["a", "b", "a"], target="a", add="x" → ["a","x","b","a","x"]
- Traverse the list
- Insert after match
- Skip inserted value
public void insertAfter(ArrayList list, String target, String toAdd) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).equals(target)) {
list.add(i + 1, toAdd);
i++;
}
}
}
- Infinite loop due to missing index increment
- Not skipping the inserted element
FRQ 7 — Shift List Left
Shift all elements one position to the left.
[A, B, C] → [B, C, A]
- Store the first element
- Remove it
- Add it to the end
public void shiftLeft(ArrayList list) {
if (!list.isEmpty()) {
Student first = list.remove(0);
list.add(first);
}
}
- Forgetting to check for empty list
FRQ 8 — Remove Adjacent Duplicate Strings
Remove all consecutive duplicate strings from the list.
["a", "a", "b", "b"] → ["a", "b"]
- Compare each element with the previous one
- Remove duplicates
- Adjust index after removal
public void removeAdjacentDuplicates(ArrayList list) {
for (int i = 1; i < list.size(); i++) {
if (list.get(i).equals(list.get(i - 1))) {
list.remove(i);
i--;
}
}
}
- Comparing wrong indices
- Forgetting to decrement index
FRQ 9 — Remove Students Below Average Score
Remove all students whose score is below the class average.
- Compute the average score
- Traverse the list again
- Remove below-average students
public void removeBelowAverage(ArrayList list) {
int total = 0;
for (Student s : list) {
total += s.getScore();
}
double avg = (double) total / list.size();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getScore() < avg) {
list.remove(i);
i--;
}
}
}
- Using integer division for average
- Removing elements in enhanced for-loop
FRQ 10 — Remove Longest Strings
Remove all strings that have the maximum length in the list.
["hi","hello","java"] → ["hi"]
- Find the maximum string length
- Traverse again and remove matching strings
public void removeLongest(ArrayList list) {
int max = list.get(0).length();
for (String s : list) {
max = Math.max(max, s.length());
}
for (int i = 0; i < list.size(); i++) {
if (list.get(i).length() == max) {
list.remove(i);
i--;
}
}
}
- Removing while calculating max length
FRQ 11 — Merge Two Sorted Integer Lists
Merge two sorted integer lists into a single sorted list.
- Use two pointers
- Compare and insert the smaller value
- Add remaining elements
public ArrayList merge(ArrayList a, ArrayList b) {
ArrayList result = new ArrayList<>();
int i = 0, j = 0;
while (i < a.size() && j < b.size()) {
if (a.get(i) <= b.get(j)) result.add(a.get(i++));
else result.add(b.get(j++));
}
while (i < a.size()) result.add(a.get(i++));
while (j < b.size()) result.add(b.get(j++));
return result;
}
- Forgetting to add remaining elements
FRQ 12 — Partition Students by Passing Status
Reorder the list so that all passing students appear before failing students.
- Create a temporary list
- Add passing students first
- Add failing students next
public void partitionPassing(ArrayList list) {
ArrayList temp = new ArrayList<>();
for (Student s : list)
if (s.isPassing()) temp.add(s);
for (Student s : list)
if (!s.isPassing()) temp.add(s);
list.clear();
list.addAll(temp);
}
- Modifying the original list during traversal
FRQ 13 — Count Unique Strings (Sorted List)
Return the number of unique strings in a sorted list.
- Compare each element with the previous one
- Count changes
public int countUnique(ArrayList list) {
if (list.isEmpty()) return 0;
int count = 1;
for (int i = 1; i < list.size(); i++) {
if (!list.get(i).equals(list.get(i - 1))) {
count++;
}
}
return count;
}
- Forgetting the list must be sorted
FRQ 14 — Find Student With Highest Score
Return the Student with the highest score.
- Track the best student
- Compare scores
public Student findTopStudent(ArrayList list) {
Student best = list.get(0);
for (Student s : list) {
if (s.getScore() > best.getScore()) {
best = s;
}
}
return best;
}
- Returning the index instead of the object
FRQ 15 — Running Total of Integers
Convert the list into a running total list.
[2, 3, 5] → [2, 5, 10]
- Maintain a cumulative sum
- Update the list using
set()
public void runningTotal(ArrayList list) {
int sum = 0;
for (int i = 0; i < list.size(); i++) {
sum += list.get(i);
list.set(i, sum);
}
}
- Creating a new list instead of modifying the original
Related FRQ Pages
- Arrays FRQs
- Strings FRQs
- 2D Arrays FRQs
- Mixed FRQs
- Full Mock FRQ Set
Need Structured Help With AP Computer Science A?
If you want guided, one-on-one support for AP Computer Science A—including FRQs, MCQs, debugging, and exam strategy—you can explore my dedicated tutoring program here:
AP Computer Science A tutoring support
https://www.javatutoronline.com/training-courses/ap-computer-science-tutor/