How To Shallow Copy Or Clone a Vector

import java.util.Vector;

public class CloneOfVector {

public static void main(String[] args) {

Vector<String> vector = new Vector<String>();
//add element in vector

// print vector
System.out.println(“Vector = “+vector);

* Returns a clone of this vector. The copy will
* contain a reference to a clone of the internal
*  data array, not a reference to the original internal
*  data array of this Vector object.

Vector<String> myvector = (Vector<String>) vector.clone();

for (String str : myvector) {

System.out.println(“element is = “+str);




Leave a Reply

Your email address will not be published. Required fields are marked *

− 6 = 3