Your basic requirement is met by any class that implements the Map interface (java.util.Map
).
However in choosing the implementation it is imperative to consider which operations you wish to optimise for:
{Insert, Delete, Random Access, Sequential Access}
If you require only random access to each question (and answer), then the HashMap
is probably your best bet.
The most common use-case of a dictionary like application is listing series of entries. Thus, if you are going to be displaying series of questions (and answers) consider using a variant of HashMap
, LinkedHashMap
.
Your basic hash table functionality is provided by HashMap
, and it will yield O(1) complexity for lookup, however iteration, required for displaying "series" or "listings" can be expensive.
In this case a LinkedHashMap
would serve your needs best because it provides a linked list tacked on to the underlying hashtable; therefore iteration or sequential access becomes inexpensive. However, the tradeoff of this is that this makes addition and deletion of new entries (questions) more expensive.