aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes adding objects to HashMap that have duplicate keys 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 » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "adding objects to HashMap that have duplicate keys" Watch "adding objects to HashMap that have duplicate keys" New topic
Author

adding objects to HashMap that have duplicate keys

Rachel Glenn
Ranch Hand

Joined: Oct 24, 2012
Posts: 95
If I have a HashMap, and I call .put() several times with the same key..for example..



Then the first put() call will return true and the second put() call will return false because the "Monday" key already exists?
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 1272
    
    7

put doesn't return a boolean. put returns the previous value. So, first call will return null and second call will return the first object
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: adding objects to HashMap that have duplicate keys
 
Similar Threads
HashMap access problem
Problem regarding HashMap.
What will if two object has the same hashcode?
HashMap values-- I think I know why but how do I fix this null pointer exception?
Reflection Usage Question