public boolean search(String word) {

        Set<TrieNode> set = new HashSet<>();
        set.add(root);
        for (int i = 0; i < word.length(); i++) {

            if (word.charAt(i) == '.') {
                Set<TrieNode> temp = new HashSet<>();
                for (TrieNode trieNode : set) {
                    for (int j = 0; j < trieNode.children.length; j++) {
                        if (trieNode.children[j] != null) {
                            temp.add(trieNode.children[j]);
                            if (i == word.length() - 1 && trieNode.children[j].isWord) return true;
                        }

                    }
                }
                set = temp;
            } else {
                Set<TrieNode> temp = new HashSet<>();
                boolean b = false;
                for (TrieNode trieNode : set) {
                    int id = word.charAt(i) - 'a';
                    if (trieNode.children[id] != null) {
                        temp.add(trieNode.children[id]);
                        b = true;
                        if (i == word.length() - 1 && trieNode.children[id].isWord) return true;
                    }
                }
                if (!b) return false;
                set = temp;
            }

        }

        return false;
    }
Returns if the word is in the data structure. A word could contain the dot character '.' to represent any one letter.
src/problems/medium/WordDictionary.java