The Enumeration Interface : Enumeration Interface « Collections « Java Tutorial






The Enumeration interface defines a way to traverse all the members of a collection of objects.

The hasMoreElements() method checks to see if there are more elements and returns a boolean.

If there are more elements, nextElement() will return the next element as an Object.

If there are no more elements when nextElement() is called, the runtime NoSuchElementException will be thrown.

import java.util.Enumeration;
import java.util.Vector;

public class MainClass {
  public static void main(String args[]) throws Exception {
    Vector v = new Vector();
    v.add("a");
    v.add("b");
    v.add("c");

    Enumeration e = v.elements();
    while (e.hasMoreElements()) {
      Object o = e.nextElement();
      System.out.println(o);
    }
  }
}
a
b
c








9.35.Enumeration Interface
9.35.1.The Enumeration Interface
9.35.2.If you prefer a for-loop
9.35.3.Where do we get the enumeration from?
9.35.4.The SequenceInputStream Class
9.35.5.Concatenates the content of two enumerations into one.
9.35.6.Filters enumeration to contain each of the provided elements just once.
9.35.7.Filters some elements out from the input enumeration.
9.35.8.For each element of the input enumeration asks the Processor to provide a replacement
9.35.9.Removes all nulls from the input enumeration.
9.35.10.Returns an enumeration that iterates over provided array.
9.35.11.Support for breadth-first enumerating.
9.35.12.Serializable Enumeration
9.35.13.An enumeration that iterates over an array.
9.35.14.Creating Custom Enumerations