Home » Java Vector copyInto() Method with Examples

Java Vector copyInto() Method with Examples

by Online Tutorials Library

Java Vector copyInto() Method

The copyInto() method of Java Vector class used to copy the elements of the vector which is in use into the specified array. In this, the position of the elements is the same in both the vector and an array.

Syntax:

Following is the declaration of copyInto() method:

Parameter:

Parameter Description Required/Optional
anArray It is the array into which the components get copied. Required

Returns:

The copyInto() method has return type void so, it does not return anything.

Exceptions:

NullPointerException– This method has thrown an exception if the specified array is null.

IndexOutOfBoundsException– This method has thrown an exception if the specified array is unable to hold all the components of this vector.

Compatibility Version:

Java 1.2 and above

Example 1:

Test it Now

Output:

Elements in an array are:   1  2  3  4  5  

Example 2:

Test it Now

Output:

Elements of the Array:   Rahul  Vijay  Shyam  Rohan  

Example 3:

Test it Now

Output:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException  at java.base/java.lang.System.arraycopy(Native Method)  at java.base/java.util.Vector.copyInto(Vector.java:200)  at myPackage.VectorCopyIntoExample3.main(VectorCopyIntoExample3.java:12)  

Next TopicJava Vector

You may also like