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.
Firstly, if this was an error it wouldn't be a compiler error. The compiler doesn't know that a Map doesn't contain duplicates. If it was an error, it would have to be at runtime.
But it's not an error anyway. There's nothing wrong with adding the same key more than once. It just won't store it more than once. If you look at the documentation for java.util.Map#put(K, V), it says:
If the map previously contained a mapping for the key, the old value is replaced by the specified value.
Joined: Jun 04, 2010
Thanks for your quick reply!!
One more question is how do we know which is the "key" and which is the "Value" in a Map ??