I have a Map having duplicate values. I now want to get the key using value without iterating through all the Map.Entries. I have more than 500 entries in the map. I do not want to iterate the whole map each time.

I thought of using BiMap of google collections. But, BiMap does not support duplicate keys. Could anyone suggest on what other thirdparty library can be used to solve this?

Update: The map contains duplicate values and it's loaded from a text file containing key value pairs.

有帮助吗?

解决方案 2

I have a Map

...well, there's your problem! It sounds like the data doesn't quite fit the limitations of a BiMap. Consider maintaining a different ordered collection of your data encapsulated as tuples (or a pair of ordered collections).

其他提示

You could use a ListMultimap and then use Multimaps.invertFrom() to get the inverse mapping.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top