simple java version of trie.