I am trying to create a distinct copy (deep copy) of a vector (for example).
This code returns a reference. Can someone point out how to accomplish this task. Thanks.
import java.util.Vector;
public class Copy{
Vector vOriginal;
Vector vCopy;
//***********************************************************************
public Copy(){
}
public static void main(
String[] args) {
Copy c = new Copy();
c.go();
}
//***********************************************************************
public void go(){
vOriginal = new Vector();
StringBuffer sb = new StringBuffer("the brown fox jumped the
fence. ");
vOriginal.add(sb);
vCopy = new Vector();
for(int i=0;i<vOriginal.size();i++){
vCopy.add(vOriginal.elementAt(i));
}
System.out.println("original: " + vOriginal.elementAt(0));
System.out.println("copy: " + vOriginal.elementAt(0));
sb.append(" The fox chased the rabbit.");
System.out.println("original: " + vOriginal.elementAt(0));
System.out.println("copy: " + vOriginal.elementAt(0));
}
}
/*
output:
original: the brown fox jumped the fence.
copy: the brown fox jumped the fence.
original: the brown fox jumped the fence. The fox chased the rabb
copy: the brown fox jumped the fence. The fox chased the rabbit.
*/