Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to copy all the elements of one vector to another vector in Java

1 Answer

0 votes
import java.util.Collections;
import java.util.Vector;

public class MyClass {
    public static void main(String args[]) { 
        Vector<String> v1 = new Vector<String>();

        v1.add("java");
        v1.add("c");
        v1.add("c++");
        v1.add("php");
        v1.add("javascript");

        Vector<String> v2 = new Vector<String>();
        
        v2.add("aa");
        v2.add("bb");
        v2.add("c");
        v2.add("dd");
        v2.add("ee");
        v2.add("ff");
        
        Collections.copy(v2, v1);

        System.out.println(v2);
    }
}
  
  
  
/*
run:
  
[java, c, c++, php, javascript, ff]

*/

 



answered Apr 19, 2020 by avibootz

Related questions

1 answer 135 views
1 answer 207 views
1 answer 132 views
1 answer 185 views
1 answer 158 views
1 answer 143 views
...