Enumeration : Java Glossary


An Enumeration is the old-style interface for going through the elements of a some sort of collection (but not a Collection) one by one. You use the Enumeration object once, then discard it.
Sample Code Implementing
Generics Learning More
Enumeration vs Iterator Links

Sample Code

You use


Enumeration has been updated to work with generics like this:

Enumeration vs Iterator

Enumeration was the forerunner of Iterator. Iterator was introduced in Java version 1.2. New classes use Iterator but the old timers still support Enumeration. You will see Enumerations in Hashtable. elements, Properties. element and Vector. elements.

If the class of interest supports both Iterator and Enumeration, use Iterator.

Enumeration vs Iterator
Enumeration Iterator Equivalent Notes
Enumeration Iterator The name of the interface the doles out the elements one by one.
Collection.iterator Typical name of method that provides the Enumeration or Iterator.
Enumeration.hasMoreElements Iterator.hasNext Are there more elements to come?
Enumeration.nextElement Iterator.next next element
java.lang.Iterable Interface noting that this class is capable of emitting an Iterator with the iterator method.
Works in a for:each statement, e. g. for ( String value : someCollection )


Implementing an Enumeration is much simpler than you might suppose. Just look at the code for some of the existing Enumerations and Iterators.

Learning More

Oracle’s Javadoc on Enumeration interface : available:
Oracle’s Javadoc on Iterator interface : available:
Oracle’s Javadoc on Iterable interface : available:

This page is posted
on the web at:


Optional Replicator mirror
of mindprod.com
on local hard disk J:

Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number