Java Collections .enumeration ( Collection <T> c)

Syntax

Collections.enumeration(Collection <T> c) has the following syntax.

public static <T> Enumeration <T> enumeration(Collection <T> c)

Example

In the following code shows how to use Collections.enumeration(Collection <T> c) method.


import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
/*ww  w .j a v a2s  .  c  o m*/
public class Main {
   public static void main(String args[]) {
      // create array list object       
      List<String> arrlist = new ArrayList<String>();
      
      // populate the list
      arrlist.add("A");
      arrlist.add("B");
      arrlist.add("from java2s.com");  
      
      // create Enumeration
      Enumeration<String> e = Collections.enumeration(arrlist);
      
      while(e.hasMoreElements()){
         System.out.println("Value is: "+e.nextElement());
      }
   }    
}

The code above generates the following result.