Convert ArrayList to String Array - Java Collection Framework

Java examples for Collection Framework:ArrayList

Description

Convert ArrayList to String Array

Demo Code


import java.util.ArrayList;
import java.util.Arrays;
 
public class Main {
        public static void main(String args[]){
                ArrayList<String> aListDays = new ArrayList<String>();
                aListDays.add("Sunday");
                aListDays.add("Monday");
                aListDays.add("Tuesday");
               /*w w  w. ja  v a 2s. com*/
                Object[] objDays = aListDays.toArray();
               
                String[] strDays = Arrays.copyOf(objDays, objDays.length, String[].class);
               
                System.out.println("ArrayList converted to String array");
               
                for(int i=0; i < strDays.length; i++){
                        System.out.println(strDays[i]);
                }
        }
}

Result


Related Tutorials