import java.util.*; public class EnumerateListExample { public static void main(String[] args) { Listcolors = new ArrayList<>(); colors.add("Red"); colors.add("Green"); colors.add("Blue"); // Get Enumeration of List elements Enumeration e = Collections.enumeration(colors); // Use Enumeration to iterate through List elements while (e.hasMoreElements()) { System.out.println(e.nextElement()); } } }
import java.util.*; public class EnumerateSetExample { public static void main(String[] args) { SetIn both examples, we use the `Collections.enumeration()` method to get an `Enumeration` of the elements in the collection. We then use the `hasMoreElements()` and `nextElement()` methods of the `Enumeration` to iterate through the elements. The `java.util Collections enumeration` belongs to the Java Collections Framework, which is a set of classes and interfaces that provide commonly used data structures and algorithms for Java programming.numbers = new HashSet<>(); numbers.add(10); numbers.add(20); numbers.add(30); // Get Enumeration of Set elements Enumeration e = Collections.enumeration(numbers); // Use Enumeration to iterate through Set elements while (e.hasMoreElements()) { System.out.println(e.nextElement()); } } }