Say I have a map of key -> value pairs, I want to reverse this so that I have a new map which is effectively value -> key (i.e. the old value becomes the new key and the old key becomes the new value).
Whats the best way to do this? (I am using Java...).
Oh and values are unique.
Personally I'd use a Guava BiMap
to start with (with an implementation such as HashBiMap
) and then call inverse()
when I wanted to use the values as keys :)
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