I am using HashMultiMap in my code. My HashMultiMap structure is like,
Key1 -> Value11 -> Value12 -> Value13 ….
Key2 -> Value21 -> Value22 ….
Now, I want if key1 has same values (example: value11 = value12) then keep (or do not store) only one copy of the value (example: keep only value11 or do not store value12). Can anybody help me how to achieve this with an efficient (faster) way.
According to the
HashMultiMapJavadoc, you chose the right MultiMap for that purpose:Now, you only have to make sure that
equals()(andhashCode()) is implemented correctly on your values. I don’t think you should worry about a faster way to do this. TheHashMultiMapshould be implemented pretty efficiently.