Home » Java programming language

Java Vector copyInto() Method with Example

Vector Class copyInto() method: Here, we are going to learn about the copyInto() method of Vector Class with its syntax and example.
Submitted by Preeti Jain, on March 15, 2020

Vector Class copyInto() method

  • copyInto() method is available in java.util package.
  • copyInto() method is used to copy all of the elements that exist in this Vector and paste it into the given object array (arr).
  • copyInto() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • copyInto() method does not throw an exception at the time of copying elements.


    public void copyInto(Object[] arr);


  • Object[] arr – represents the container of copied elements.

Return value:

The return type of the method is void, it returns nothing.


// Java program to demonstrate the example 
// of void copyInto(Object[] arr) method 
// of Vector 

import java.util.*;

public class CopyIntoOfVector {
    public static void main(String[] args) {
        // Instantiates a Vector object  with
        // initial capacity of "10"
        Vector < String > v = new Vector < String > (10);
        String str[] = new String[5];

        // By using add() method is to add the
        // elements in this v

        // Display Vector
        System.out.println("v: " + v);

        System.out.println("str: ");
        for (String s: str)
            System.out.println("str[]: " + s);

        // By using copyInto() method is to copy 
        // all of the elements of this vector v
        // in to a string array str[]

        System.out.println("v.copyInto(str): ");
        for (String s: str)
            System.out.println("str[]: " + s);


v: [C, C++, JAVA]
str[]: null
str[]: null
str[]: null
str[]: null
str[]: null
str[]: C
str[]: C++
str[]: JAVA
str[]: null
str[]: null

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.