Assigning an array to an ArrayList in Java

You can use Arrays.asList():

Type[] anArray = ...
ArrayList<Type> aList = new ArrayList<Type>(Arrays.asList(anArray));

or alternatively, Collections.addAll():

ArrayList<Type> aList = new ArrayList<Type>();
Collections.addAll(theList, anArray); 

Note that you aren’t technically assigning an array to a List (well, you can’t do that), but I think this is the end result you are looking for.

Leave a Comment