4

When is it useful to work with the Java class Enumeration and why is it useful to work with it?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
John Doe
  • 259
  • 1
  • 6
  • 18

1 Answers1

6

Enumeration is largely obsolete. Per the Javadoc, it is an interface that generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series. It is the predecessor to Iterator which (per the Javadoc)

Iterator takes the place of Enumeration in the Java Collections Framework.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • 2
    Iterator was added in Java 1.2 (1998) ;) – Peter Lawrey Sep 14 '15 at 20:29
  • 1
    @PeterLawrey Which is also when Collection(s) were added. Apache Commons Collections provides [`EnumerationIterator`](http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.1/org/apache/commons/collections/iterators/EnumerationIterator.html) which can be used to make an `Enumeration` appear as an `Iterator`. – Elliott Frisch Sep 14 '15 at 20:34
  • `Enumeration` is for code archaeologists – Peter Lawrey Sep 15 '15 at 06:40