In Java, Collections.list(e) reads an Enumeration from start to finish and returns a brand-new ArrayList containing its elements in the same order.
It is the bridge from old APIs (Vector, Hashtable, StringTokenizer, some servlet methods) to modern collection code, where you can sort, filter, and loop with for-each.
A static method of the java.util.Collections utility class, available since Java 1.4. Call it on the class name, as in Collections.list(...), after import java.util.Collections;. You never create a Collections object.
Syntax
Pass the enumeration; you get an ArrayList, not just a List.
Java
ArrayList<String> items = Collections.list(vector.elements());
ArrayList<Object> words = Collections.list(new StringTokenizer("a b c"));
Call
What it does
Collections.list(e)
New ArrayList with every remaining element of e.
Collections.enumeration(c)
The opposite direction: collection to Enumeration.
new ArrayList<>(vector)
If you already hold the collection, copy it directly.
Available since Java 1.4. The return type is the concrete class ArrayList<T>, so the result is fully changeable and independent of the source.
Library declarations
Java
// java.util.Collections
public static <T> ArrayList<T> list(Enumeration<T> e)
Parameters
Parameter
Description
e
The enumeration to drain. Must not be null.
Return Value
Return Value
Description
ArrayList<T>
A new list with the elements in the order the enumeration returned them.