Answered by : 2-programmers-1-bug
Integer[] spam = new Integer[] { 1, 2, 3 };
List<Integer> list = Arrays.asList(spam);
Source : https://stackoverflow.com/questions/2607289/converting-array-to-list-in-java | Last Update : Wed, 04 Mar 20
Answered by : glamorous-gharial-batwola70bu7
List<Element> list = Arrays.asList(array);
Source : https://dzone.com/articles/how-convert-array-arraylist | Last Update : Fri, 29 May 20
Answered by : jolly-jaguar-1ehuq10pdhdc
{"tags":[{"tag":"textarea","content":"List<String> list = new ArrayList<>();\nlist.add(\"pizza\");\nlist.add(\"dosa\");\nlist.add(\"biryani\");\n\n\/\/returns an array of String, hence better!!\nString[] array1 = list.toArray(new String[0]);\n\n\/\/returns an array of Object\nObject[] array2 = list.toArray();","code_language":"java"}]}
Source : | Last Update : Sat, 28 Jan 23
Answered by : dark-dove-rm13txcuxevu
List<String> list = new ArrayList<>();
list.add("a");
list.add("ab");
list.add("abc");
list.add("abcd");
// convert
String[] array = list.toArray();
Source : | Last Update : Mon, 16 Mar 20
Answered by : bucket-ofjava
ArrayList<String> ArrayLister=new ArrayList<>(){ArrayLister.add("Hi")};
String[] array=ArrayLister.toArray(String[]);
Source : | Last Update : Fri, 15 May 20
Answered by :
Integer[] arr = new Integer[al.size()]; // ArrayList to Array Conversion for (int i = 0; i < al.size(); i++) arr[i] = al.get(i);
Source : | Last Update : Fri, 20 Nov 20
Answered by : arno
String[][] w = allProducts.toArray(new String[][] {});
Source : https://stackoverflow.com/questions/8031630/how-to-convert-from-an-arraylist-of-arrays-to-an-array-of-arrays | Last Update : Sun, 24 Apr 22
Answered by : encouraging-elephant-0i1da2km167f
Integer[] arr = new Integer[al.size()];
for (int i = 0; i < al.size(); i++) arr[i] = al.get(i);
Source : | Last Update : Fri, 20 Nov 20
Answered by : jinal-patel
ArrayList<Integer> list = new ArrayList<>(OtherList);
//it will copy all elements from OtherList to this one
//time complexity - O(n)
Source : | Last Update : Fri, 13 Aug 21
Answered by : wrong-wryneck-0f0q5yjj5k82
You can only use the to array method if you convert to any object type.
Source : | Last Update : Wed, 23 Dec 20