Enumeration Interface in Java

Google Advertisements

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

Syntax

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
v.add(10);
v.add(20);
v.add(30);

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

while(itr.e.hasMoreElements())
{  
System.out.println(e.e.nextElements());  
  }  
 }  
}  

Output

Forword Direction
10
20
30

Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs