indexOf changed example

This commit is contained in:
mherbaghinyan 2019-01-11 15:05:34 +04:00
parent 9e9458ea5f
commit ea5039f1a1
1 changed files with 7 additions and 12 deletions

View File

@ -20,24 +20,19 @@ public class MatchWords {
ahoCorasick();
wordIndices(inputString);
indexOfWords(inputString, items);
}
private static void wordIndices(String inputString) {
Map<Integer, String> wordIndices = new TreeMap<>();
List<String> words = new ArrayList<>();
words.add("hello");
words.add("Baeldung");
private static boolean indexOfWords(String inputString, String[] words) {
boolean found = true;
for (String word : words) {
int index = inputString.indexOf(word);
if (index != -1) {
wordIndices.put(index, word);
if (index == -1) {
found = false;
break;
}
}
wordIndices.keySet().forEach(System.out::println);
return found;
}
private static boolean containsWords(String inputString, String[] items) {