AP® Computer Science A glossary
indexOf
Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods
The String method indexOf(String str), which returns the index of the first occurrence of str, or -1 if str is not found.
Appears in the course and exam description (CED): 1.15.B.2
Only the first occurrence counts. A result of -1 means not found, so check it before using it as an index.
String word = "INTERFACE";
System.out.println(word.indexOf("E"));
System.out.println(word.indexOf("X"));
Output:
3
-1 Learn it properly, with a checkpoint 1.15 String Manipulation