Possible Duplicate:
Any implementation of Map<K1, K2, V>, i.e. two keys?
I need to store name and id as key value pair. However I need to look up by both name and id at times in my program. I don’t want to create two HashMap (or double the memory consumption by storing name-id and id-name pair)
What is a suitable data structure for it? Is there a Standard implementation in java for this?
You can use also guava’s BiMap. And to get the inverse map is as simple as:
The only constraint is that your keys and values should be unique.