Re: vector addElement



On Tue, 31 Jul 2007 04:51:13 -0700, korcs <konrad.lindner@xxxxxxx>
wrote, quoted or indirectly quoted someone who said :

The problem is, that it seems to me, that the addElement method adds
the row_container to the end of the vector and then changes the value
of all its previous instances.

I think what you are disturbed about is when you write:

v1 = new Vector();
....
v2 = v1;

v2.addElement( x );

When you look at v1 it has x too.

This is because there is only one Vector object and both v1 and v2
point to it. This is a general Java object problem, not just Vectors.

To get round it you must make a copy of the Vector object, either
field by field into a new Vector or by using the clone() method. See
http://mindprod.com/jgloss/clone.html

By the way, Vector is almost never used these days, supplanted by
ArrayList.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.