Hello. I have a map list updated during condition procedure and at the end of the procedure I add the map to the arraylist before the second update.
when I print the map before I add it to the arraylist it shows me correct answer but when I print the arraylist at the end it gives me the same result for all the maps inside it.
it seems like it copying the last map into multiple items instead of adding a different map in the arraylist each time I use add.
The code up shows that when I print the map it shows me different answer each time I call it.
put at then end the all result of this arrylist is the same
Like Steve says we need to see code but it's probably because you aren't creating a new instance of the map during your "condition procedure" and so you are adding the same map instance to the list multiple times. Also if you are using the same keys each time through the "condition procedure" the map will entries will be overwritten each time and so each list entry will show as being the last map returned by your "condition procedure".
feras almasri wrote:The mistake was that I didn't use new map each time I want to add a new map in the list. but I can't understand why it needs that?
Thanks
Because you're not actually adding the map to the list, you are adding a reference to the map. So if you added the 'map' to the list several times, all you actually have is a list of references to the same map. If you then change the map, all those references will be pointing to the changed map.
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss