Почему у меня не останавливается следующий алгоритм?
В приведенном ниже коде str — это строка, в которой я ищу, а findStr — это вхождения строки, которую я пытаюсь найти.
String str = "helloslkhellodjladfjhello";
String findStr = "hello";
int lastIndex = 0;
int count = 0;
while (lastIndex != -1) {
lastIndex = str.indexOf(findStr,lastIndex);
if( lastIndex != -1)
count++;
lastIndex += findStr.length();
}
System.out.println(count);
Подробнее здесь: https://stackoverflow.com/questions/767 ... n-a-string