• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

overriding the array....

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic