Enumeration is an interface class in Java.util that encapsulates methods for enumerating data collections in enumeration.
Public interface Enumeration<e> { /** * Tests If this enumeration contains more elements. * * @return <code>true</code> if and only if the enumeration object * contains at least one m ore element to provide; * <code>false</code> otherwise. * /Boolean hasmoreelements ();/** * Returns The next element of this enumeration if this enumeration * OBJEC t have at least one more element to provide. * * @return The next element of this enumeration. * @exception nosuchelementexception If no more elements exist. * /E nextelement (); }
Public Interface Enumeration<e> implements the enumeration interface object, which generates a series of elements, one at a time.
There are two methods of enumeration:
hasmoreelements () tests whether this enumeration contains more elements.
nextelement () returns the next element of this enumeration if there is at least one element that can be supplied by this enumeration object. Successive calls to the Nextelement method will return a series of contiguous elements.
For example, to output all elements of vector<e> V, you can use the following methods:
for (enumeration<e> E = v.elements (); e.hasmoreelements ();) System.out.println (E.nextelement ());
These methods are enumerated primarily through the elements of the vector, the keys of the Hashtable, and the values in the hash table. The enumeration is also used to assign an input stream to Sequenceinputstream.
Note: The functionality of this interface is duplicated with the functionality of the Iterator interface.
Additionally, the Iterator interface adds an optional remove operation and uses a shorter method name. The new implementation should prioritize the use of the Iterator interface instead of the enumeration interface.
JAVA Enumeration (list)