Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashMap

 
shree vijay
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we add duplicate items in a hashmap as in
MyHashMap.put("Shree",7000);
MyHashMap.put("Shree",9000);
when i ask to print out the contents using an iterator, i see that only the last stored value is valid.
That is,
I get Shree 9000
What exactly happens out there? Is the first reference removed and the new one added?


------------------
Regards,
Shree
 
Brian, Cavanagh
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shree,
this is taken from javadoc for the put() of HashMap
"If the map previously contained a mapping for this key, the old
* value is replaced."
HTH,
Brian C
 
shree vijay
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Brian, where do you look up for the javadoc?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the API for 1.3
http://java.sun.com/j2se/1.3/docs/api/index.html
Scroll down the left to find hashmap and click on it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic