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,914 questions

51,847 answers

573 users

How to convert ArrayList<String> to String array (String[]) in Java

2 Answers

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

public class MyClass {
    public static void main(String args[]) {
        ArrayList<String> al = new ArrayList<String>();
   
        al.add("java");
        al.add("c");
        al.add("php");
        al.add("python");
        al.add("c++");
          
        String[] arr = al.toArray(new String[0]);
   
        Arrays.stream(arr).forEach(e->System.out.print(e + " ")); 
    }
}
   
   
   
/*
run:
   
java c php python c++ 
   
*/

 



answered Dec 4, 2019 by avibootz
edited Nov 15, 2023 by avibootz
0 votes
import java.util.ArrayList;

public class MyClass {
    public static void main(String args[]) {
        ArrayList<String> al = new ArrayList<String>();
    
        al.add("java");
        al.add("c");
        al.add("php");
        al.add("python");
        al.add("c++");
           
        String[] arr = al.toArray(new String[al.size()]);  
    
        for(String s : arr) {  
            System.out.println(s);  
        }  
    }
}
    
    
    
    
/*
run:
    
java
c
php
python
c++
    
*/

 



answered Jun 28, 2020 by avibootz
edited Nov 15, 2023 by avibootz

Related questions

5 answers 411 views
5 answers 273 views
1 answer 160 views
1 answer 116 views
1 answer 145 views
1 answer 121 views
1 answer 211 views
...