String[] arr = list.toArray(new String[list.size()]);
List<Element> list = Arrays.asList(array);
List<String> list=new ArrayList<String>();
list.add("sravan");
list.add("vasu");
list.add("raki");
// Conversion part
String names[]=list.toArray(new String[list.size()])
List<String> list = new ArrayList<>();
list.add("a");
list.add("ab");
list.add("abc");
list.add("abcd");
// convert
String[] array = list.toArray();
ArrayList<String> ArrayLister=new ArrayList<>(){ArrayLister.add("Hi")};
String[] array=ArrayLister.toArray(String[]);
Integer[] arr = new Integer[al.size()];
for (int i = 0; i < al.size(); i++)
arr[i] = al.get(i);
List<Integer> list = ...;
int[] array = new int[list.size()];
for(int i = 0; i < list.size(); i++) array[i] = list.get(i);
List<String> stockList = new ArrayList<String>();
stockList.add("stock1");
stockList.add("stock2");
String[] stockArr = new String[stockList.size()];
stockArr = stockList.toArray(stockArr);
for(String s : stockArr)
System.out.println(s);
List<Foo> list = new ArrayList<>();
Foo[] array = list.toArray(new Foo[0]);
String[][] w = allProducts.toArray(new String[][] {});
Integer[] arr = new Integer[al.size()];
arr = al.toArray(arr);
ArrayList<Integer> list = new ArrayList<>(OtherList);
//it will copy all elements from OtherList to this one
//time complexity - O(n)
You can only use the to array method if you convert to any object type.