Skip Top Navigation Bar

AP CSA Student Practice

Strings

For the AP Exam, you will need to use the following methods:

Use the following examples to learn and practice creating String objects and using each of these methods. NOTE: Instead of System.out we are using IO. IO is not on the AP Exam and it works identically to System.out. On the AP exam, you will continue to see System.out.

Creation: Creation and assign simple strings of characters

length(): Getting the Length of a String

substring(): Getting a Substring from a String and an Index

indexOf: Finding the Index of a String in Another String

equals: Comparing Strings with == and equals()

compareTo: Using compareTo() to Get the Rank of a Name in Alphabetical Order

split: Splitting a String of Characters with split()