I need to store a few hundred strings in a data structure. Every string has two fields associated with it, like say word meaning and its origin.I can store the words in any fashion, say sorted,reverse sorted or anyway you like.
I just need to search for a string within the dictionary as quickly as possible and fetch the two related fields. If possible, I want my search to be even better than the binary search.
I am using Java. Which data structure or Collection Class should I use ?
Note : I do not want to use database in this.
You can use a
HashMap<String,MyDataObject>– it will be fastest and simplest to use.Average seek time is
O(|S|), where|S|is the string’s length.You can also try and use a trie or a radix tree, but make sure you want to give the time for it by profiling the
HashMapsolution before you start working on it.