Enumeration : Java Glossary

go to home page E words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish 2006-03-08 by Roedy Green ©1996-2009 Canadian Mind Products
index page for letter ⇒ punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
Enumeration
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 it like this:

Generics

Enumeration has been updated to work with generics like this:

Enumeration vs Iterator

Enumeration was the forerunner of Iterator. Iterator was introduced in JDK 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.
Hashtable.elements
Properties.propertyNames
Vector.elements
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

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

Sun’s Javadoc on the Enumeration class : available:
Sun’s Javadoc on the Iterator class : available:
Sun’s Javadoc on the Iterable class : available:

CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.62] Spread the Net
You are visitor number 19,671.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/enumeration.html J:\mindprod\jgloss\enumeration.html