Vector clone() Method in Java with Examples
The clone() method of Vector class is used to return a shallow copy of this vector. It just creates a copy of the vector. The copy will have a reference to a clone of the internal data array but not a reference to the original internal data array.
Parameters: The method does not take any parameter.
Return Value: The method returns an Object which is just the copy of the vector.
CloneNotSupportedException − This exception is thrown if the object’s class does not support the Cloneable interface.
Below programs illustrate the Java.util.vector.clone() method:
Vector: [Welcome, To, Geeks, 4, Geeks] The cloned vector is: [Welcome, To, Geeks, 4, Geeks]
Vector: [10, 15, 30, 20, 5] The cloned vector is: [10, 15, 30, 20, 5]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.