Please explain your problem clearly. It looks like you are confusing "unique" and "non-unique". HashMap requires 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
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop