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

Total Post:117

Points:821
Posted on    May-04-2015 12:04 AM

 Java Java  Array  Array List 
Ratings:


 2 Reply(s)
 605  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

Points:3117
Supported
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

Points:21
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