Unit 1 Day 11: Substring Method Practice
Share
Unit 1, Section 1.11
Day 11 Practice • January 17, 2026
🎯 Focus: Substring Method
Practice Question
Consider the following code segment:
String s = "APEXAM";
System.out.println(s.substring(1, 4) + s.substring(4));
What is printed as a result of executing this code segment?
What This Tests: This question tests the substring() method with both one and two parameters. Understanding that the end index is exclusive is crucial for the AP exam.
Key Concept: substring() Parameters
// Index: 0 1 2 3 4 5
// String: A P E X A M
s.substring(1, 4) // From index 1 up to (NOT including) 4 → "PEX"
s.substring(4) // From index 4 to the end → "AM"
Step-by-Step Trace
| Expression | Indices Used | Result |
|---|---|---|
| s.substring(1, 4) | Indices 1, 2, 3 | "PEX" |
| s.substring(4) | Indices 4, 5 | "AM" |
| "PEX" + "AM" | Concatenation | "PEXAM" |
Common Mistakes
Mistake: Including the end index
substring(1, 4) does NOT include index 4. The end parameter is exclusive. Think of it as "up to but not including."
substring() Rules
💡 Remember This Pattern
substring(start) → From start to the end
substring(start, end) → From start to end-1
Length of result: end - start
Difficulty: Medium • Time: 1-2 minutes • AP Skill: 2.C - Call methods
Want More Practice?
Master AP CSA with guided practice and expert help
Schedule 1-on-1 Tutoring Practice FRQs