Tại sao thuật toán sau không tạm dừng đối với tôi? (str là chuỗi tôi đang tìm kiếm, findStr là chuỗi tôi đang cố gắng tìm)
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);