I need a collection in Java that is going to store a pair, a key and a value.
So I decided to use a HashMap<String,String>
, but I noticed that when I try to add a key that already exists, the previous (key,value) is replaced by the new one (NewKey,NewValue) and the previous entry is lost. So when I have duplicate keys, the previous key is replaced by the new one.
How can I have a HashMap with duplicate keys?