CREATE ARRAYLIST (ARRAYLIST<T>) FROM ARRAY (T[])..

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
 1061  View(s)
Ratings:
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. Mayank Tripathi

    Post:397

    Points:3117
    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);

  1. wushiwu08 wushiwu08

    Post:3

    Points:21
    Re: Create ArrayList (ArrayList<T>) from array (T[])

    Post is removed by the Admin.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!