Fixed a bug in findWord method
@@ -12,10 +12,13 @@ public class WordIndexer {
String lowerCaseWord = word.toLowerCase();
while(index != -1) {
- index = lowerCaseTextString.indexOf(lowerCaseWord, index + 1);
- if (index != -1) {
- indexes.add(index);
+ index = lowerCaseTextString.indexOf(lowerCaseWord, index);
+ if (index == -1) {
+ break;
}
+
+ indexes.add(index);
+ index++;
}
return indexes;
}
