we have a following code :
Vector a ; // containing some struct info
Vector b;
b = a ;
if we modify b does it affect on the containing of a ?
we have a following code :
Vector a ; // containing some struct info
Vector b;
b = a ;
if we modify b does it affect on the containing of a ?
Yes. Both b and a will refer to the same instance of Vector on the heap. This happens with any object, including arrays.
Let's say vector a lies at a hypothetical place called 12345 on the heap. a's value(since A is a reference) is 12345. When b=a is done, b equals 12345 as well. Dereferencing b will land you on the same place on the heap hence the same object.
Yes! That's a flat copy. To make a deep copy, use Collections:
Vector b = new Vector(a.size());
b.setSize(a.size());
Collections.copy(b,a);
Hope that helps.
edit:
hexafraction is right, the better answer is (using the copy constructor):
Vector b = new Vector(a);