1List<String> list = new ArrayList<>();
2list.add("a");
3list.add("ab");
4list.add("abc");
5list.add("abcd");
6// convert
7String[] array = list.toArray();
1import java.util.ArrayList;
2public class ListToArray {
3 public static void main(String args[]){
4 ArrayList<String> list = new ArrayList<String>();
5 list.add("Apple");
6 list.add("Orange");
7 list.add("Banana");
8
9 System.out.println("Contents of list ::"+list);
10 String[] myArray = new String[list.size()];
11 list.toArray(myArray);
12
13 for(int i=0; i<myArray.length; i++){
14 System.out.println("Element at the index "+i+" is ::"+myArray[i]);
15 }
16 }
17}
1ArrayList<String> ArrayLister=new ArrayList<>(){ArrayLister.add("Hi")};
2String[] array=ArrayLister.toArray(String[]);
3