Eric <an*******@discussions.microsoft.com> wrote:
I have an array, result[][]. I populate the array and add it to an
ArrayList. I then change result[][] and add the new version to the
ArrayList. However, when I go to review the ArrayList, all of the
result[][] 's are the same. How can I stop this from happening? I
tried copying the array but that didn't work.
You're not adding the actual array to the ArrayList - you're adding a
reference. You're then adding the same reference (i.e. a reference to
the same object) later on, just changing the data inside the object.
You need to make a copy of the array, and change the copy and then add
that. You say that didn't work - please post the code.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too