aspose file tools
The moose likes Java in General and the fly likes HashMap Duplicate Key should give error? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "HashMap Duplicate Key should give error?" Watch "HashMap Duplicate Key should give error?" New topic
Author

HashMap Duplicate Key should give error?

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 225
the following code should have given me error for "duplicate" key. but it is not giving. why?



The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
Anuj Prashar
Ranch Hand

Joined: Apr 15, 2008
Posts: 99

It is just replacing the value mapped by key 'word'. It is not creating any new entry in map.

After first call of put method a mapping is created.
And for any subsequent call to put method if the map contained a mapping for key, the old value is replaced.


SCJP 5,SCWCD 5, RHCT
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 225
Anuj Prashar wrote:It is just replacing the value mapped by key 'word'. It is not creating any new entry in map.

but it should give error "duplicate entry" (word). isn't it so ?
Anuj Prashar
Ranch Hand

Joined: Apr 15, 2008
Posts: 99

check this this

After first call, subsequent call to put method will replace old value if mapping for key you are using in your put method already exist.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashMap Duplicate Key should give error?
 
Similar Threads
HashMap remove multiple elements
Validation for the Indexed properties dynamic fields in struts (JSP)
MultiDimenaional Array sort
LinkedHashMap - trying to use the method removeEldestEntry
Help with logic:equal