Java | Trie | Clean Code
Prerequisites : Leetcode Implement Trie Data Structure\n\n#### Solution : \n\n\n\nclass WordDictionary {\n    \n    private static final int ALPHABETS = 26;\n  
***Prerequisites*** : [Leetcode Implement Trie Data Structure](https://github.com/abhisheksurve45/leetcode-may-2020#week-2)\n\n#### Solution : \n\n```\n\nclass WordDictionary {\n    \n    private static final int ALPHABETS = 26;\n    \n    /** TrieNode class contains child TrieNode and end to denote end of particular word  */\n    private class TrieNode {\n        private TrieNode[] child = new TrieNode[ALPHABETS];\n        private boolean end;\n    }\n    \n    private TrieNode root;\n\n    /** Initialize your data structure here. */\n    public WordDictionary() {\n        this.root = new TrieNode();\n    }\n    \n    /** Adds a word into the data structure. */\n    public void addWord(String word) {\n        TrieNode trieNode = root;\n        for(Character c : word.toCharArray()){\n            int index = c - \'a\';\n            if(trieNode.child[index]== null){\n                trieNode.child[index] = new TrieNode();\n            }\n            trieNode = trieNode.child[index];\n        }\n        trieNode.end = true;\n    }\n    \n    /** Returns if the word is in the data structure. A word could contain the dot character \'.\' to represent any one letter. */\n    public boolean search(String word) {\n        return match(word.toCharArray(), root, 0);\n    }\n    \n    private boolean match(char[] word,TrieNode node, int index) {\n        \n\t\t/** word is not present in trie, return false */\n        if(node == null) return false;\n        \n\t\t/** word of exact length found in trie, return if it is a valid word (TrieNode.end) */\n        if(index == word.length) return node.end;\n        \n        char ch = word[index];\n        \n        /* for ".", run matching condition for every alphabet */\n        if(ch == \'.\') {\n            \n            for(int i = 0; i< ALPHABETS ; i++) {\n                if (node.child[i] != null && match(word, node.child[i], index+1)) {\n                    return true;\n                }\n            }\n             \n        } else {\n            /*  for normal character, check if child node is present & matches */\n            return node.child[ch - \'a\'] != null && match(word, node.child[ch - \'a\'], index+1);\n        }\n        \n        /* return false default  */\n        return false;\n        \n    }\n}\n\n/**\n * Your WordDictionary object will be instantiated and called as such:\n * WordDictionary obj = new WordDictionary();\n * obj.addWord(word);\n * boolean param_2 = obj.search(word);\n */\n \n```\n\nPlease upvote!\n\n---\nMore such solutions can be found here : [Github](https://github.com/abhisheksurve45/leetcode-aug-2020)\n---
['Trie', 'Java']