Is there a java structure like HashMap but that allows to repeat the key as well as the value ?
For example:
HashMap<Integer, String> hmap = new HashMap<>();
map.put(1, "Sport");
map.put(1, "Football");
map.put(2, "Football");
map.put(1, "Handball");
And as a result:
<1,"Sport">
<1,"Football">
<2,"Football">
<3,"Handball">
Any help would be most appreciated.
Thanks, Nadhmanovic
There is not a structure like this built into the language. But you can use Guava's Multimap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With