The indexOf(String str) method is used to find the index position of the first occurrence of a specified substring within a larger string.
Imagine you have a book and you want to find out on which page a specific word appears for the first time. The indexOf(String str) method works similarly by searching for the first occurrence of a substring within a larger string and returning its index position.
lastIndexOf(String str): This method finds the index position of the last occurrence of a specified substring within a larger string.
contains(CharSequence sequence): This method checks if a sequence of characters exists within another string and returns true or false accordingly.
replace(CharSequence target, CharSequence replacement): This method replaces all occurrences of one sequence with another sequence within a given string.
Study guides for the entire semester
200k practice questions
Glossary of 50k key terms - memorize important vocab
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.