![]() |
VOOZH | about |
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.
Vector: [1, 2, 3] The initial array is: 10 20 30 The final array is: 1 2 3
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.
Vector: [Geeks, For, Geeks] The initial array is: Hello World Java The final array is: Geeks For Geeks