What is the best way to implement a three item hashMap?
For example, I would like to use a regular String key , but have it map to two different objects. The idea is like having a list of lists, except that the first item is a key.
I am trying to avoid iterating through the list ( so the behavior is like a hashmap ). Would you agree the only way is to build a new Class? It seems a “HashMap3” object ( with methods of get1( key ) & get2( key ) ) would be useful. I am unsure of how to set this up myself.
How can I create the collection?
If the key will always map to exactly two Objects, then the easiest way to do this is to make a
Pairclass that exists only to hold the two objects. Then you use your String as the key and thePairinstance as the value. However, if the key can map to arbitrarily many Objects, then IMO the best way to do this is to have the value stored in theMapbe aCollectionof some sort.