Overview and Actualizing the Topic

Bonjour, learner! Today's session revolves around Java's string methods, particularly those used for searching and replacing. Imagine this scenario: you're managing a chatroom code of conduct and need to search for inappropriate text to replace it. In this lesson, we will explore the procedure.

String Searching: The 'indexOf' and 'lastIndexOf' Methods

Our exploration begins with a string search. Java provides the indexOf() and lastIndexOf() methods. indexOf() returns the index of the first occurrence of a substring, while lastIndexOf() yields the index of the last.

In this example, the term "CodeSignal" begins at index 7 in our string.

Notice how "CodeSignal" starts at index 27 in the last occurrence within our string. Efficient, isn't it?

Checking Substring Existence: The 'contains' Method

The contains() method confirms whether a string contains a specific sequence of characters, regardless of its location.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal