VOOZH about

URL: https://www.geeksforgeeks.org/java/vector-clone-method-in-java-with-examples/

⇱ Java Vector clone() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Vector clone() Method

Last Updated : 11 Jul, 2025

In Java, the clone() method of the Vector class is used to return a shallow copy of the 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.

Example 1: In this example, we use the clone() method to create the shallow copy of a vector of integer type.


Output
The Original Vector is: [100, 200, 300]
The Cloned Vector is: [100, 200, 300]

Syntax of Vector clone() Method

public Object clone()

Return Type: It returns an object which is just the copy of the vector. 

Example 2: In this example, we create a shallow copy of a vector of string type.


Output
The Original Vector is: [Geeks, For, Geeks]
The Cloned Vector is: [Geeks, For, Geeks]


Example 3: To better understand shallow copying, here's an example using a vector containing mutable objects.


Output
The Original Vector is: [Hello, Geeks]
The Cloned Vector is: [Hello, Geeks]
After modification: 
The Original Vector is: [Hello Java, Geeks]
The Cloned Vector is: [Hello Java, Geeks]
Comment