Collections enumeration() method in Java with Examples Last Updated : 08 Jun, 2021 Comments Improve Suggest changes Like Article 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 Comment More infoAdvertise with us Next Article Collections enumeration() method in Java with Examples rohitprasad3 Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions +1 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Java Collections emptyEnumeration()â Method with Examples The emptyEnumeration() method of Java Collections is used to get the empty enumeration that contains no elements in Java. Syntax: public static <T> Enumeration<T> emptyEnumeration() Parameters: This method has no parameters. Return Type: This method will return an empty enumeration. Exce 2 min read Collection contains() method in Java with Examples The contains(Object element) of java.util.Collection interface is used to check whether the element 'element' exists in this collection. This method returns a boolean value depicting the presence of the element. If the element is present, it returns true, else it returns false. Syntax: Collection.co 3 min read Java Collections emptyListIterator() Method with Examples The emptyListIterator() method of Java Collections is a method that is used to iterate the List with no elements in Java. Syntax: public static <T> ListIterator<T> emptyListIterator() Parameters: It has no parameters. Return Type: It will return the list with empty elements. Exceptions: 2 min read Collections list() method in Java with Examples The list() method of java.util.Collections class is used to return an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration. This method provides interoperability between legacy APIs that return enumerations and new APIs that requi 2 min read Java Collection containsAll() Method with Examples The Collection interface in Java is the fundamental part of the Collection hierarchy. It is found in the java.util package and offers a wide range of built-in classes and methods. One such useful method is containsAll(). Java containsAll() methodThe purpose of this containsAll() is to check whether 3 min read Collection add() Method in Java with Examples The add(E element) of java.util.Collection interface is used to add the element 'element' to this collection. This method returns a boolean value depicting the successfulness of the operation. If the element was added, it returns true, else it returns false. Syntax: Collection.add(E element) Paramet 4 min read Collections checkedCollection() method in Java with Examples The checkedCollection() method of java.util.Collections class is used to return a dynamically typesafe view of the specified collection. The returned collection does not pass the hashCode and equals operations through to the backing collection, but relies on Object's equals and hashCode methods. Thi 3 min read Collections fill() method in Java with Examples The fill() method of java.util.Collections class is used to replace all of the elements of the specified list with the specified element. This method runs in linear time. Syntax: public static void fill(List list, T obj) Parameters: This method takes following argument as parameter list - the list t 2 min read Collections addAll() method in Java with Examples The addAll() method of java.util.Collections class is used to add all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this 3 min read AbstractCollection add() Method in Java with Examples The add() method in Java AbstractCollection is used to add a specific element into a Collection. This method will add the element only if the specified element is not present in the Collection else the function will return False if the element is already present in the Collection. Syntax: AbstractCo 2 min read Like