Home > DeveloperSection > Forums > Create ArrayList (ArrayList<T>) from array (T[])..
jayprakash sharma
jayprakash sharma

Total Post:117

Posted on    May-04-2015 12:04 AM

 Java Java  Array  Array List 

 2 Reply(s)
 638  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 = ???;

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    May-04-2015 12:38 AM

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

wushiwu08 wushiwu08
wushiwu08 wushiwu08

Total Post:3

Posted on    May-09-2015 12:33 AM

Post is removed by the Admin.

Don't want to miss updates? Please click the below button!

Follow MindStick