This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Please explain your problem clearly. It looks like you are confusing "unique" and "non-unique". HashMaprequires that keys are unique.
The Apache Jakarta Commons Collections library contains extra collection classes that aren't in the standard Java API. Maybe class MultiKeyMap or MultiValueMap in that library is what you are looking for?
I think you typed "unique" when you meant "duplicate". "HashMap does not allow duplicate keys." is true.
This is a common enough problem that the solution has a name: MultiMap. You can find implementations of MultiMap in the Apache Commons and other places, but the idea is so simple you can make your own.
The idea is for each key we store a List of values instead of a single value. Here's how put works in a class that has a map as a member variable. Can you imagine get?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi