How To Convert ArrayList to String Array In Java

Here toArray() method of List interface facilitates to convert list to¬†array which contains the list’s elements.

Here we are taking example for arraylist to string array conversion.


package com.startwithjava
import java.util.ArrayList;
import java.util.List;

public class StartWithJava {
public static void main(String args[]){
List list = new ArrayList<String>();
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
list.add("Five");

String[] stringArray = new String[al.size()];
al.toArray(stringArray);

for(String str : stringArray)
System.out.println(str);

}
}

Leave a Reply