Convert Collection to List [duplicate]

I would like to ask: how do you convert a Collection to a List in Java?


Collection<MyObjectType> myCollection = ...;
List<MyObjectType> list = new ArrayList<MyObjectType>(myCollection);

See the Collections trail in the Java tutorials.


If you have already created an instance of your List subtype (e.g., ArrayList, LinkedList), you could use the addAll method.

e.g.,

l.addAll(myCollection)

Many list subtypes can also take the source collection in their constructor.


List list;
if (collection instanceof List)
{
  list = (List)collection;
}
else
{
  list = new ArrayList(collection);
 }