Untitled Document

Subscribe here to get updates on new Videos

 

23. Three Cursors of Java - Enumeration?

 

 

 

previous homenext

If we want to retrieve Objects one by one from the Collection, then we should go for Cursors.
There are three types of cursors are available in Java.

Enumeration
Iterator
ListIterator Enumeration:


Introduced in 1.0 version (for legacy)

We can use Enumeration to get Objects one by one from the old Collection Objects(Legacy Collection).
We can create Enumeration Object by using elements() method of Vector Class. Public Enumeration elements();

Example:

Enumeration e=v.elements();

Method of Enumeration

Enumeration defines the following two methods

1. public Boolean hasMoreElements();
2. public Object nextElement();

Limitations of Enumeration:

1. Enumeration concept is applicable only for legacy classes and hence it is not a universal cursor.
2. By using Enumeration we can get only read access and we can’t perform remove operation.


Note: To overcome above limitations of Enumeration we should go for iterator.