Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Java – Enumeration

Declaration

interface Enumeration<E>

Enumeration interface is a legacy interface.

It is used to obtain one element at a time, from the collections.

It is been superseded by Iterator interface.

Enumeration object is created using elements() method of vector class.

List of Enumeration Methods (CLICK HERE)

Example

 import java.util.Enumeration;
 import java.util.Vector;

 public class EnumerationInterfaceDemo 
 {
     public static void main(String args[])
     {
         Vector<String> lang = new Vector<String>();
         lang.add("C");
         lang.add("C++");
         lang.add("Java");
         lang.add("C#");
         lang.add("Python");
         lang.add("Kotlin");
		
         Enumeration<String> e = lang.elements();
         while(e.hasMoreElements())
         {
             System.out.println(e.nextElement());
         }
     }
 }

Output

C
C++
Java
C#
Python
Kotlin

 

Leave a reply