Find all occurrences of the word "the" without using regex
Just some ideas: 

The code should work as it is and is OK if performance doesn't matter, or the searched strings are small and occurrences few.


You don't need to call both contains(...) and indexOf(...); this iterates through the string twice.
The substring method copies the whole remaining string into a new string. 


Easiest way is to call indexOf(String s, int fromIndex), with the start index parameter. 

You can also build a state machine, representing how many letters of "the" have been found sequentially. Then analyze the string char by char.

Also keep in mind that your search will not work for repeating character sequences: if you search for "thethe" instead, and your searched text contains "thethethe", it will be found only once, although it occurs twice. Because your next index skips the entire search phrase when found (here by hardcoded "3"). It depends on what the demands are in your case, and what to do with such search phrases.