Create ArrayList from array

Ron Tuffin picture Ron Tuffin · Oct 1, 2008 · Viewed 1.5M times · Source

I have an array that is initialized like:

Element[] array = {new Element(1), new Element(2), new Element(3)};

I would like to convert this array into an object of the ArrayList class.

ArrayList<Element> arraylist = ???;

Answer

Tom picture Tom · Oct 1, 2008
new ArrayList<>(Arrays.asList(array));