I working with this code
while((dictionaryWord = br_.readLine()) != null)
{
if(dictionaryWord.matches("^"+word.replace("*" , "." )+"$"))
{
incrementCounter();
System.out.println(dictionaryWord);
}
}
Desired Goal: word = dgo
Output: dog, god, dogma megalogdon, etc….
You can build a
Set<Character>of all the chars inword, and iterate it. If one character is not indictionaryWord, thendictionaryWorddoes not fit. Only if all appear – printdictionaryWordIn the above code, the set creation can be moved out of the
whileloop, of course.More efficient solution could be to create a
SetfromdictionaryWordas well, and then check if the intersection of the two sets is identical to the set representingword.This will be:
using
CollectionUtils.intersection()from apache commons