data get duplicated on a Vector

Hey,

I really need help

while using Vector and adding elements, I get this problem:
I add the 1st element: OK
I add the 2nd element: 2 elements in the vector, but the first element gets the value of the second element
I add the 3rd element: the vector contains 3 elements, all have the value of the 3rd element
..and so on

here is the source code (written only the essential not to make it complicated for you)

while using Vector and adding elements, I get this problem:
I add the 1st element: OK
I add the 2nd element: 2 elements in the vector, but the first element gets the value of the second element
I add the 3rd element: the vector contains 3 elements, all have the value of the 3rd element
..and so on

That's a symptom that you store one single object in your Vector multiple times; when you change the content of one of them, 'all' (mind the quotes) of them in your Vector change.

If I post the initialization part, it will get complicated for you and no one will ever read it
I made sure with debugging that x1,x2,x2 are initialized correctly and the problem occurs at the "addElement" method level.

When you add an object to a Collection you add the reference to that object and not the object itself.

Lets pretend that a piece of paper stuck to the wall is your array. You write "dog", "cat" and "monkey". On the paper. You then get John to point at the paper. You then cross out "cat" and replace it with "pig" and get Mike to point at the piece of paper.

Now your expectations is that John is pointing to a different piece of paper than Mike is pointing at. Whereas they are both pointing at the same piece of paper with dog, pig and monkey written on it.

thanks for the explanation,
to fix that, I added "chromosome_buf = new int[500]" at the beginning of the loop, so that each time I get a new memory allocation for the array. but still the same problem...
how would you fix the problem if it were you ?