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  

Collections:
  1. Collections
  2. Get empty collection from Collections
  3. Do binary search
  4. Copy value to a List
  5. Get Enumeration from collection, create list from Enumeration
  6. Fill a list
  7. Get the max and min value from a Collection
  8. Fill n Copy object to a list
  9. Replace value in a list
  10. Reverse a list
  11. Get comparator in reverse order
  12. Rotate and shuffle a list
  13. Create singleton
  14. Sort a list
  15. Swap element in a list
  16. Get a synchronized collection
  17. Return an unmodifiable view of collections