Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

According to the Java API, Interface Enumeration<E> documentation [API 2011],

An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series.

...

Unfortunately, a Vector and an Enumeration may not always work well together. In fact, the Java API [API 2011] recommends, "New implementations should consider using Iterator in preference to Enumeration." Consequently, iterators rather than enumerators should be preferred when examining iterable collections.

...

According to the Java API, Interface Iterator<E> documentation [API 2011],

Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways:

  • Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
  • Method names have been improved.

...

Using Enumeration when performing remove operations on a vector may cause unexpected program behavior.

Bibliography

[API 2011]Interface Enumeration<E>
Interface Iterator<E>
[Daconta 2003]Item 21, "Use Iteration over Enumeration"

...