Enumeration Interface in Java

Prev Tutorial Next Tutorial

Enumeration Interface in Java

It is one of the predefined interface and whose object is always used for retrieving the data from any legacy collection framework variable (like vector, stack, HasTable etc.) only in forward direction but not in backward direction. Like Iterator interface object, Enumeration Interface object is pointing just before the first element of any legacy collection framework variable.

The functionality of Enumeration is more or less similar to Iterator Interface but Enumeration Interface object belongs to synchronized and Iterator Interface object belong to non-synchronized.

Points to Remember

  • Enumeration does not support addition, removing and replacing og elements.
  • Enumeration is Synchronized.
  • Using Enumeration elements of legacy collection can be access only in forward direction.
  • Every legacy class contains following methods to work with enumeration and it returns enumeration object.

Methods of Enumeration Interface

  • public boolean hasMoreElements(): Return true if Enumeration contains more elements otherwise returns false.
  • public object nextElement(): Returns the next elements of Enumeration.

Create an object of Enumeration


Vector v=new Vector();
Enumeration e=v.elements();

Example of Enumeration

import java.util.Arraylist;

class EnumerationDemo
public static void main(String args[])

Vector<Integer> al=new vector<Integer>();  // creating Vector

Enumeration e=v.elements();
System.out.println("Forword Direction");  



Forword Direction

Prev Tutorial Next Tutorial

Download Projects

Google Adsense Advertisements
Free Classified Site – Bedpage

Yahoo Advertisements