Skip to main content

AP CSA FRQ Guide

2016 FRQ 2: LogMessage

Parse log messages into machine and description fields, detect a whole word in a description, and remove matching messages from a system log.

String Parsing and ArrayList Removal22 minute targetStringsubstringindexOfArrayListremoval

Skills Tested

What this FRQ is really practicing

StringsubstringindexOfArrayListremoval

Review these topics before attempting the problem.

Starter Approach

How to begin with your own plan

  1. 1Constructor: split at the colon and store the two parts.
  2. 2containsWord: find whole-word matches, not just substrings.
  3. 3removeMessages: remove matching messages without skipping entries, and return them in their original order.

Attempt the problem before opening the solution.

Common Mistakes

Mistakes to watch for while writing

Counting a keyword that appears as part of a larger word.
Skipping the item after a removal in a forward loop.
Forgetting to add removed messages to the result list.
Appending while traversing backward, which reverses the required returned-message order.

Self Check

Review questions before you submit

Splits the message at the colon.

indexOf(":") followed by substring is a common approach.

Checks word boundaries around the keyword.

A keyword inside another word should not count.

Removes matching messages without skipping elements.

Loop backward or adjust the index after removal.

Returns the removed messages in their original order.

A backward removal traversal must insert each removed item at the front of the returned list; forward traversal may append.

Practice Links

Where to go next