Collections enumeration() method in Java with Examples Last Updated : 08 Jun, 2021 Comments Improve Suggest changes 3 Likes Like Report The enumeration() method of java.util.Collections class is used to return an enumeration over the specified collection. This provides interoperability with legacy APIs that require an enumeration as input.Syntax: public static Enumeration enumeration(Collection c) Parameters: This method takes the collection c as a parameter for which an enumeration is to be returned.Return Value: This method returns an enumeration over the specified collection.Below are the examples to illustrate the enumeration() methodExample 1: Java // Java program to demonstrate // enumeration() method // for String value import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // creating object of List<String> List<String> arrlist = new ArrayList<String>(); // Adding element to srclst arrlist.add("Ram"); arrlist.add("Gopal"); arrlist.add("Verma"); // Print the list System.out.println("List: " + arrlist); // creating object of type Enumeration<String> Enumeration<String> e = Collections.enumeration(arrlist); // Print the Enumeration System.out.println("\nEnumeration over list: "); // print the enumeration while (e.hasMoreElements()) System.out.println("Value is: " + e.nextElement()); } catch (IllegalArgumentException e) { System.out.println("Exception thrown : " + e); } catch (NoSuchElementException e) { System.out.println("Exception thrown : " + e); } } } Output: List: [Ram, Gopal, Verma] Enumeration over list: Value is: Ram Value is: Gopal Value is: Verma Example 2: Java // Java program to demonstrate // enumeration() method // for Integer value import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // creating object of List<Integer> List<Integer> arrlist = new ArrayList<Integer>(); // Adding element to srclst arrlist.add(20); arrlist.add(30); arrlist.add(40); // Print the list System.out.println("List: " + arrlist); // creating object of type Enumeration<Integer> Enumeration<Integer> e = Collections.enumeration(arrlist); // Print the Enumeration System.out.println("\nEnumeration over list: "); // print the enumeration while (e.hasMoreElements()) System.out.println("Value is: " + e.nextElement()); } catch (IllegalArgumentException e) { System.out.println("Exception thrown : " + e); } catch (NoSuchElementException e) { System.out.println("Exception thrown : " + e); } } } Output: List: [20, 30, 40] Enumeration over list: Value is: 20 Value is: 30 Value is: 40 Create Quiz Comment R rohitprasad3 Follow 3 Improve R rohitprasad3 Follow 3 Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions +1 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like