This can be done by iterating myString
and shifting fromIndex
parameter in indexOf()
:
int currentIndex = 0;
while (
myString.indexOf(
mySubstring,
currentIndex) >= 0) {
System.out.println(currentIndex);
currentIndex++;
}