• Post Reply Bookmark Topic Watch Topic
  • New Topic

Values of HashMap keys are overriden  RSS feed

 
AdityaSushma Sharma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm creating a HashMap. While creating it, I can see that keys are assigned proper distinct values, but, after creation, when I iterate it, all the keys are yielding only one value. Below is my code (accountMap is a class level variable -
private HashMap<String, Object> accountMap = new HashMap<String, Object>();
):

And here is my console output:

Since the value stored in HashMap is a bean, I'm printing one property of the bean for every key. The output shows that value for all keys is getting overridden by the last accessed key's value. I'm not able to figure out where am I making the wrong move (I know it's bad!!).
Hope I'm clear with question. If not, please let me know the caveat and I shall fill it. Thanks in advance!!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does GAAccountBean look like? Are maybe its member variables static?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!