VOOZH about

URL: https://www.geeksforgeeks.org/java/vector-copyinto-method-in-java/

⇱ Java Vector copyInto() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Vector copyInto() Method

Last Updated : 11 Jul, 2025

In Java, the copyInto() method is used to copy all the components from one vector to another array, having enough space to hold all of the components of the vector. It is to be noted that the index of the elements remains unchanged. The elements present in the array are replaced by the elements of the vector starting from index 0.

Example: Here, we use the copyInto() method to copy all the elements from a Vector into an array of type Integer.


Output
Vector: [1, 2, 3]
The initial array is: 10 20 30 
The final array is: 1 2 3 

Syntax of Vector copyInto() Method

public void copyInto(Object[] array )

Parameter: The parameter array[] is of the type vector. This is the array into which the elements of the vector are to be copied. 

Exceptions:

Example 2: Here, we use the copyInto() method to copy all the elements from a Vector into an array of type String.


Output
Vector: [Geeks, For, Geeks]
The initial array is: Hello World Java 
The final array is: Geeks For Geeks 
Comment