AP® Computer Science A glossary

substring

Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods

String methods substring(from, to), which returns the characters from index from to to - 1, and substring(from), which goes to the end.

Appears in the course and exam description (CED): 1.15.B.21.15.B.3

The number of characters returned is to - from. substring(i, i + 1) gives the single character at index i.

String word = "INTERFACE";
System.out.println(word.substring(0, 5));
System.out.println(word.substring(5));
System.out.println(word.substring(2, 3));

Output:

INTER
FACE
T
Learn it properly, with a checkpoint 1.15 String Manipulation

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure