java.util.Collections.enumeration() Method
Advertisements
Description
The enumeration(Collection<T>) method is used to get an enumeration over the specified collection.
Declaration
Following is the declaration for java.util.Collections.enumeration() method.
public static <T> Enumeration<T> enumeration(Collection<T> c)
Parameters
c--This is the collection for which an enumeration is to be returned.
Return Value
The method call returns an enumeration over the specified collection.
Exception
NA
Example
The following example shows the usage of java.util.Collections.enumeration()
package com.tutorialspoint;
import java.util.*;
public class CollectionsDemo {
public static void main(String args[]) {
// create array list object
List arrlist = new ArrayList();
// populate the list
arrlist.add("A");
arrlist.add("B");
arrlist.add("C");
// create Enumeration
Enumeration e = Collections.enumeration(arrlist);
System.out.println("Print the enumeration");
while(e.hasMoreElements()){
System.out.println("Value is: "+e.nextElement());
}
}
}
Let us compile and run the above program, this will produce the following result.
Print the enumeration Value is: A Value is: B Value is: C