Java Collections - enumeration() Method
The java.util.Collections.enumeration() method returns an enumeration over the specified collection.
Syntax
public static <T> Enumeration<T> enumeration(Collection<T> c)
Here, T is the type of element in the list.
Parameters
c |
Specify the collection for which an enumeration is to be returned. |
Return Value
Returns an enumeration over the specified collection.
Exception
NA.
Example:
In the example below, the java.util.Collections.enumeration() method returns an enumeration over the given collection.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a list object List<String> MyList = new ArrayList<String>(); //populating MyList MyList.add("Alpha"); MyList.add("Coding"); MyList.add("Skills"); //creating enumeration over the list Enumeration e = Collections.enumeration(MyList); //printing the enumeration System.out.println("Enumeration contains: "); while(e.hasMoreElements()) System.out.println(e.nextElement()); } }
The output of the above code will be:
Enumeration contains: Alpha Coding Skills
❮ Java.util - Collections