TrieTree { public List<String> prefixSearch(String key) { List<String> value = new ArrayList<String>(); if (StringUtil.isEmpty(key)) { return value; } char k = key.charAt(0); int index; if (Character.isUpperCase(k)) { index = k - UPPERCASE_STAR; } else { index = k - LOWERCASE_STAR; } if (root.children != null && root.children[index] != null) { return query(root.children[index], value, key.substring(1), String.valueOf(k)); } return value; } TrieTree(); void insert(String data); List<String> prefixSearch(String key); List<String> all(); List<String> depth(Node node, List<String> list, char[] chars, int index);  }
@Test public void prefixSearch() throws Exception { TrieTree trieTree = new TrieTree(); trieTree.insert("abc"); trieTree.insert("abd"); trieTree.insert("ABe"); List<String> ab = trieTree.prefixSearch("AB"); for (String s : ab) { System.out.println(s); } System.out.println("========"); }
@Test public void prefixSearch8() throws Exception { TrieTree trieTree = new TrieTree(); List<String> ab = trieTree.prefixSearch(""); String result = ""; for (String s : ab) { result += s + ","; System.out.println(s); } Assert.assertTrue(result.equals("")); }