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

Total Post:117


 1624  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);


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.