What if I need to quickly search not only by the key but also by value. In other words, is there a construction like key-key as opposed to key-value?
Sounds like you want a bimap - I'd use the implementations in Guava if I were you; there's a BiMap interface, and various implementations such as HashBiMap and ImmutableBiMap.
Note that you generally view a BiMap from one "side" (K1 to K2), and just call inverse() to get the opposite view of things (K2 to K1).
Several libraries have something like that. For example, Google Guava has a BiMap (bidirectional map). Unfortunately there's no bidirectional map in the standard Java library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With