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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sounds like you want a bimap – I’d use the implementations in Guava if I were you; there’s a
BiMapinterface, and various implementations such asHashBiMapandImmutableBiMap.Note that you generally view a
BiMapfrom one “side” (K1 to K2), and just callinverse()to get the opposite view of things (K2 to K1).