This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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: 2339
    
  28

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
 
 
subject: adding objects to HashMap that have duplicate keys