Java array to list to array conversions with inbuilt features.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxoNBrrho4Kn1fCogwiYNw9zpkl6hV3mfVaSn1kjiQeNesPY99Plx7Sp1emCIXLq5LKoWorTZJbajiPeul8eYOYxpxqxrNyl97XjkVZq5L39JYy77HcJKNteL7l4VSFF45EJg7tw/s1600/Java+list+to+array+to+list+www.digizol.com.png)
import java.util.List;
import java.util.Arrays;
String[] array = {"one", "two", "three"};
List newListObject = Arrays.asList(array);
//adding to existing List
String[] newArray = {"four", "five"};
List all = new ArrayList();
all.addAll(newListObject);
all.addAll(Arrays.asList(newArray));
Also creating a new Array object using an existing List object can be done using another for() loop; by creating a new Array object with a size matching to list size and adding each on at a time. But for this requirement, there are a set of methods.
List list = new ArrayList();
list.add("one");
list.add("two");
Object[] array1 = list.toArray(); //1
String[] array2 = (String[])list.toArray(new String[0]); //2
String[] array3 = new String[2];
list.toArray(array3); //3
With Line #1, returned array is of Object type, while #2 returns a new array object of String type.
Line #3 uses the same method used in #2, but in this case we have provided an array object with the same size as the list. Because of that in line #3, the provided array object is populated with list elements.
COMMENTS