Enumeration

In this chapter you will learn:

  1. Get Enumeration from collection, create list from Enumeration

Get Enumeration from collection, create list from Enumeration

  • static<T> Enumeration<T> enumeration(Collection<T> c)
    Returns an enumeration for a collection.
  • static<T> ArrayList<T> list(Enumeration<T> e)
    Create an ArrayList from an enumeration.
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
/*from   java  2  s  .  c  o m*/
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:

Next chapter...

What you will learn in the next chapter:

  1. How to use EnumSet
  2. How to create EnumSet with a list of enum value list
Home » Java Tutorial » Collections
Iterator
ListIterator
Collection unmodifiable
Collection synchronized
Collection singleton
Collection max/min value
Empty Collections
Comparator
Comparable
Enumeration
EnumSet
EnumMap Class
PriorityQueue