PrepGo

AP Computer Science A Flashcards: String Manipulation

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Review key ideas with interactive flashcards. This set includes 10 cards to help you master important concepts.

What is the range of valid index values for a String object?
A String object has index values from 0 to one less than the length of the string.
Card 1 of 10

All Flashcards (10)

What is the range of valid index values for a String object?
A String object has index values from 0 to one less than the length of the string.
What is String Concatenation?
String concatenation is the process of combining strings using the + or += operator, which always results in a new String object.
Why does combining or calling methods on a String always result in a new String object rather than modifying the original?
This is a direct consequence of a String object being immutable. Since the original object's attributes cannot be changed, any operation that alters the string must create a new object.
Can a primitive value, such as an integer, be combined with a String object?
Yes, a primitive value can be concatenated with a String object, resulting in a new String object.
What is the result of calling a method (e.g., toUpperCase()) on a String object?
Methods called on a String object do not change the content of the original String object; they typically return a new String object with the result.
Define "immutable" in the context of a String object.
A String object is immutable, meaning once a String object is created, its attributes cannot be changed.
What exception is thrown when code attempts to access an index outside the valid range of a String?
Attempting to access indices outside the valid range of a String will result in a StringIndexOutOfBoundsException.
How can two String objects be combined, and what is the outcome?
Two String objects can be concatenated using the + or += operator, which results in the creation of a new String object.
Consider the code: `String s = "AP"; s += "CS";`. Does this change the original String object containing "AP"?
No, the original String object is not changed because it is immutable. The `+=` operator creates a new String object and reassigns the variable `s` to it.
If `String str = "Java";`, what is the index of the last character 'a'?
The index of the last character 'a' is 3, because String indices range from 0 to one less than the length of the string.