I am use this source:
String fulltext = "I would like to create a book reader have create, create ";
String subtext = "create";
int i = fulltext.indexOf(subtext);
but I find only the first index, how to find all first indexes in the string ? (in this case three index)
After you've found the first index, use the overloaded version of indexOf
that receives the start index as a second parameter:
public int indexOf(int ch, int fromIndex)
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
Keep doing that until indexOf
returns -1
, indicating that there are no more matches to be found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With