Java solution using HashMap data structure
Create HashMap<Integer, ArrayList<String>> to store words in specific lists mapped to their length. This will drastically reduce the number of words that will b
Create ```HashMap<Integer, ArrayList<String>>``` to store words in specific lists mapped to their length. This will drastically reduce the number of words that will be searched for.\n\n```\nimport java.util.regex.Pattern;\nclass WordDictionary {\n    // Mapping word length as the key and the list of words as the value\n    Map<Integer, ArrayList<String>> map;\n    /** Initialize your data structure here. */\n    public WordDictionary() {\n        map = new HashMap<Integer, ArrayList<String>>();\n    }\n    \n    /** Adds a word into the data structure. */\n    public void addWord(String word) {\n        ArrayList<String> list;\n        if(map.get(word.length()) != null) list = map.get(word.length());\n        else list = new ArrayList<String>();\n        list.add(word);\n        map.put(word.length(), list);\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        ArrayList<String> list;\n        if(map.get(word.length()) != null) list = map.get(word.length());\n        else return false;\n        if(list.contains(word)) return true;\n        else {\n            Pattern regex = Pattern.compile(word);\n            for (String s:list) {\n                if (regex.matcher(s).matches()) return true;\n            }\n        }\n        return false;\n    }\n}\n```
['Java']