AP CSA Student Practice
Review Videos
Check out the AP CSA review video series.
Strings
For the AP Exam, you will need to use the following methods:
int length()String substring(int from, int to)String substring(int from)int indexOf(String str)boolean equals(Object other)int compareTo(String other)String[] split(String del)
Use the following examples to learn and practice creating String objects and using each of these methods.
Creating and Assigning Simple Strings of Characters
Learn how to create and assign a String variable in Java, and see what happens when you reassign it.
Learn what happens when you assign one String variable to another, and then reassign the first one.
Learn what happens when you assign one String variable to another, and then reassign the first one.
Learn what happens when you assign one String variable to another, and then reassign the first one.
Getting the Length of a String with the length() Method
Learn how to use the
length()method to get the number of characters in a StringLearn how to use the
length()method on several String variables and compare their lengths.Learn how
length()reflects the new value of a String after concatenation and reassignment.Getting the length of an empty String, and how it grows when characters are concatenated to it.
Getting a Substring from a String and an Index with substring()
Finding the Index of a String in Another String with indexOf()
Comparing Strings with == and equals()
Using compareTo() to Get the Rank of a Name in Alphabetical Order
Learn how
compareTo()handles strings that differ only in case.Learn how to use
compareTo()to determine the alphabetical rank of a string among a group of values.