indexOf changed example

This commit is contained in:
mherbaghinyan 2019-01-11 15:05:34 +04:00
parent 9e9458ea5f
commit ea5039f1a1

View File

@ -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) {