• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding the array....

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i have loop, inside the loop i set the value for the array object called
month_with_data
then,i set the value to map

map.put("months"+i, month_with_data);//i is a counter

but outside loop,if i want to get map.get(months0)....it showing the current iteration value..(it is overriding..i want the key /value fair)..

so ,is there any way to prevent this ?

please explain me...

thanks & regards,
seetharaman
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difficult to understand your problem.
Are you putting the same object into the Map several times? If so you wil get the same object back, and it will change date as you wait.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is indeed unclear. But, whatever I get out of it is:

You are filling an array object with some date/month type strings or something. Now, then you are feeding this to a map by map.put("months"+i, month_with_data);//i is a counter . Finally, when you try to retrieve values from map you get the key distinct but, value is always the last index in array.

If it's like so, then the simple thing is that you are doing something wrong while filling your Array.

Also, ("months"+i, month_with_data); is not the correct way of doing things. A map is a key-value pair. Now, what you are doing is you are assosiating an entire array object to a key. Well, what I understand is that you don't want that. What you want is simple key-month instance relationship. So, instead of binding the Array just, bind the month instances directly to the key.
The map wouldn't automatically understand that, it has got a collection and should attach the keys for that automatically.

Well, it would be better if you could make the problem more clear unless it is something different.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic