I’m trying to use indexOf to find all occurrences of the characters ‘the’ in a sentence. For example, if the sentence were “The other day I went over there”, it should return 3. I am able to do this …
Tag: indexof
Finding second occurrence of a substring in a string in Java
We are given a string, say, “itiswhatitis” and a substring, say, “is”. I need to find the index of ‘i’ when the string “is” occurs a second time in the original string. String.indexOf(“is”) will return 2 in this case. I want the output to be 10 in this case. Answer Use overloaded version of indexOf(), which takes the starting index