indexOf changed example
This commit is contained in:
parent
9e9458ea5f
commit
ea5039f1a1
@ -20,24 +20,19 @@ public class MatchWords {
|
|||||||
|
|
||||||
ahoCorasick();
|
ahoCorasick();
|
||||||
|
|
||||||
wordIndices(inputString);
|
indexOfWords(inputString, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void wordIndices(String inputString) {
|
private static boolean indexOfWords(String inputString, String[] words) {
|
||||||
Map<Integer, String> wordIndices = new TreeMap<>();
|
boolean found = true;
|
||||||
List<String> words = new ArrayList<>();
|
|
||||||
words.add("hello");
|
|
||||||
words.add("Baeldung");
|
|
||||||
|
|
||||||
for (String word : words) {
|
for (String word : words) {
|
||||||
int index = inputString.indexOf(word);
|
int index = inputString.indexOf(word);
|
||||||
|
if (index == -1) {
|
||||||
if (index != -1) {
|
found = false;
|
||||||
wordIndices.put(index, word);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return found;
|
||||||
wordIndices.keySet().forEach(System.out::println);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean containsWords(String inputString, String[] items) {
|
private static boolean containsWords(String inputString, String[] items) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user