Вопрос

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