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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 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 77 views
1 answer 36 views
36 views asked Mar 15, 2023 by avibootz
1 answer 78 views
1 answer 71 views
71 views asked Apr 29, 2020 by avibootz
...