java util Enumeration Interface
Enumeration Interface in Java
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.
Methods are provided to enumerate through the elements of a vector, the keys of a hashtable, and the values in a hashtable. Enumerations are also used to specify the input streams to a SequenceInputStream.
It is possible to adapt an Enumeration to an Iterator by using the asIterator() method.
The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.
In this tutorial you can learn about java.util.Enumeration Interface and its examples. And also learn how to use java.util.Enumeration Interface.
java.util.Enumeration Interface Example
Use of java.util.Enumeration in SequenceInputStream class found in the java.io package. The class has a constructor that accepts an Enumeration.
Following Example will be executed successfully whenever 3 files i.e. file1.txt, file2.txt and file3.txt exists in the current directory of this example.
Create above three files with any text in those files and run the example, the example displays the contents of these 3 files.
How to use Java Enumeration Interface with SequenceInputStream
You will learn how to create custom Enumeration from the following example.
How to create custom Enumeration
In the following Java Enumeration example, you can learn how to create Java Enumeration using String Array
How to create Java Enumeration using String Array