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.

40,011 questions

51,958 answers

573 users

How to convert Vector to array in Java

2 Answers

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

public class MyClass {
    public static void main(String args[]) {
        Vector<String> vector = new Vector<String>(); 
   
        vector.add("java"); 
        vector.add("c++"); 
        vector.add("c"); 
        vector.add("php"); 
 
        Object[] obj = vector.toArray(); 
   
        String[] array = Arrays.copyOf(obj, obj.length, String[].class); 
   
        System.out.println(Arrays.toString(array)); 
    }
}
 
 
 
 
/*
run:
 
[java, c++, c, php]
 
*/


 



answered May 19, 2020 by avibootz
edited Aug 21, 2023 by avibootz
0 votes
import java.util.Vector;
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        Vector<String> vector = new Vector<String>(); 
   
        vector.add("java"); 
        vector.add("c++"); 
        vector.add("c"); 
        vector.add("php"); 
 
        String[] array = vector.toArray(new String[vector.size()]);
   
        System.out.println(Arrays.toString(array)); 
    }
}
 
 
 
 
/*
run:
 
[java, c++, c, php]
 
*/

 



answered May 19, 2020 by avibootz
edited Aug 21, 2023 by avibootz

Related questions

1 answer 124 views
1 answer 99 views
99 views asked Mar 15, 2023 by avibootz
1 answer 127 views
127 views asked Apr 29, 2020 by avibootz
1 answer 146 views
146 views asked Apr 29, 2020 by avibootz
1 answer 38 views
1 answer 112 views
...