Get Enumeration from collection, create list from Enumeration
static<T> Enumeration<T> enumeration(Collection<T> c)
- Returns an enumeration over the specified collection.
static<T> ArrayList<T> list(Enumeration<T> e)
- Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
public class Main {
public static void main(String args[]) throws Exception {
Vector<String> v = new Vector<String>();
v.add("a");
v.add("b");
v.add("java2s.com");
Collection<String> col = v;
Enumeration<String> e = Collections.enumeration(col);
for (; e.hasMoreElements();) {
Object o = e.nextElement();
System.out.println(o);
}
}
}
The output:
a
b
java2s.com
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
public class Main {
public static void main(String[] args) {
Vector<String> v = new Vector<String>();
v.add("A");
v.add("B");
v.add("D");
v.add("E");
v.add("java2s.com");
System.out.println(v);
Enumeration<String> e = v.elements();
ArrayList<String> aList = Collections.list(e);
System.out.println(aList);
}
}
The output:
[A, B, D, E, java2s.com]
[A, B, D, E, java2s.com]
Home
Java Book
Collection
Java Book
Collection
Collections:
- Collections
- Get empty collection from Collections
- Do binary search
- Copy value to a List
- Get Enumeration from collection, create list from Enumeration
- Fill a list
- Get the max and min value from a Collection
- Fill n Copy object to a list
- Replace value in a list
- Reverse a list
- Get comparator in reverse order
- Rotate and shuffle a list
- Create singleton
- Sort a list
- Swap element in a list
- Get a synchronized collection
- Return an unmodifiable view of collections