01
Overview

Detecting word boundaries to extract initials.

Spaces (and the start of the string) mark where words begin. The first letter of each word forms the initials.

A word boundary is either the start of the String or a position right after a space. The character at a word boundary is the first letter of that word — exactly what initials are made of.

The classic FRQ: given "Maria Carlos Rodriguez", return "MCR". The algorithm scans the String and grabs the character whenever a boundary is detected.

On the AP exam, word-boundary problems appear in name-parsing and acronym FRQs.

02
Core Concept

First char is always taken; later chars only after a space.

Two rules combined into one loop.

Initials extraction

public String getInitials(String name) {
    if (name.length() == 0) return "";
    String initials = "" + name.charAt(0);   // first letter always
    for (int i = 1; i < name.length(); i++) {
        if (name.charAt(i - 1) == ' ' && name.charAt(i) != ' ') {
            initials += name.charAt(i);
        }
    }
    return initials;
}

Why check the previous char

The boundary test asks "is this position right after a space?" That's charAt(i - 1) == ' '. Combined with "and not itself a space", we identify the start of each word.

Edge cases

  • Empty string: return empty initials.
  • Single word: return just the first letter.
  • Multiple spaces in a row: the extra != ' ' check prevents grabbing nothing.
  • Leading space: handled by the loop starting at index 1.

Convert to uppercase

initials = initials.toUpperCase();

Most prompts want uppercase initials. Apply at the end or per-character.

03
Key Vocabulary

Word-boundary vocabulary.

Used in name parsing.

Vocabulary
  • Word boundary — position where a new word begins.
  • Initials — first letters of each word.
  • Whitespace — space, tab, newline characters.
  • Previous-char check — looking back to detect boundaries.
  • Edge case — input that needs special handling (empty, single word, etc.).
04
AP Exam Focus

How word boundaries are tested.

Previous-char detection and boundary edge cases dominate.

Exam Focus
  • First char is always a word start. Handle outside the loop.
  • Check charAt(i - 1) == ' ' for "after space".
  • Skip leading/double spaces. Combined check prevents empty matches.
  • Start loop at index 1. Avoids out-of-bounds on i - 1.
05
Worked Example

Extract initials from "Maria Carlos Rodriguez".

Trace the boundary detection.

Worked Example AP-style reasoning

Input: "Maria Carlos Rodriguez".

  • First char 'M' → initials = "M".
  • i=5: charAt(4)=' ', charAt(5)='C' → boundary. initials = "MC".
  • i=12: charAt(11)=' ', charAt(12)='R' → boundary. initials = "MCR".
  • All other positions: previous char is a letter; no append.

Final: "MCR".

For " Bob" (leading double space):

  • First char ' ' → initials = " " (problem: starts with space).
  • To fix: skip leading whitespace before grabbing the first letter, or check the first char isn't a space.
06
Common Mistakes

Word-boundary pitfalls.

Most miss the first letter or grab spaces.

Watch Out
  • Forgetting the first char. Loop only catches boundaries after spaces.
  • Loop from index 0 checking i - 1. Crashes — start at 1.
  • Grabbing the space. Without the != ' ' check, double spaces produce empty initials.
  • Empty input. charAt(0) crashes on empty string.
07
Reference Table

Boundary detection logic.

Two conditions, combined.

Word Boundary Reference

AP Quick Reference
PositionConditionAction
Index 0Always a boundaryGrab the char.
InteriorcharAt(i-1) == ' ' && charAt(i) != ' 'Grab the char.
Loop starti = 1Avoids OOB.
Edge: emptylength == 0Return "".
08
Practice Tip

How to master word boundaries.

First char separately; then scan for "after space".

Practice Strategy
  • MCQ Practice — for each option, verify the first char is handled and loop starts at 1.
  • Java Lab — write getInitials, countWords, capitalizeWords. Test on names with double spaces.
  • FRQ Practice — handle the first char outside the loop; then check i - 1 inside.
09
Section · 09

Practice — attempt these now.

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

FRQ Practice 30 min 18 marks Pending

AP CSA Unit 12 Topic 08 Word Boundaries and Initials FRQ Practice

AP-style topic practice assessment

Start