Create ArrayList (ArrayList<T>) from array (T[])..

Posted by  jayprakash sharma
 1802  View(s)
Rate this:
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 = ???;
  1. Re: Create ArrayList (ArrayList<T>) from array (T[])

    new ArrayList<Element>(Arrays.asList(array))

    You probably just need a List, not an ArrayList. In that case you can just do:

    List<Element> arraylist = Arrays.asList(array);