java.util

Interface Enumeration<E>

Known Subinterfaces:
NamingEnumeration<T>
Known Implementing Classes:
Array, IteratorEnumeration, NamespaceSupport.Prefixes, StringTokenizer, TernaryTree.Iterator

public interface Enumeration<E>

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.

For example, to print all elements of a vector v:

     for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
         System.out.println(e.nextElement());
}

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.

NOTE: 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.

Since:
JDK1.0
See Also:
Iterator, SequenceInputStream, nextElement(), Hashtable, Hashtable.elements(), Hashtable.keys(), Vector, Vector.elements()

Method Summary

boolean
hasMoreElements()
Tests if this enumeration contains more elements.
E
nextElement()
Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Method Details

hasMoreElements

public boolean hasMoreElements()
Tests if this enumeration contains more elements.
Returns:
true if and only if this enumeration object contains at least one more element to provide; false otherwise.
Usages and Demos :

View More Examples of hasMoreElements()
   1: import java.util.Vector;
   2: import java.util.Enumeration;
   3: 
   4:         ...
   5:       if (modeMap != null) {
   6:         for (Enumeration enum = modeMap.values();
   7:         ...
   8:              enum.hasMoreElements()
   9:              && attributeProcessing != Mode.ATTRIBUTE_PROCESSING_FULL;)

View Full Code Here
   1: import java.rmi.RemoteException;
   2: import java.util.Enumeration;
   3: import java.util.Vector;
   4:         ...
   5:         try {
   6:             for (Enumeration en = messages.elements();
   7:         ...
   8:                  en.hasMoreElements() & !terminated; ) {
   9:                 printer.printIt(en.nextElement().toString());

View Full Code Here
   1:     
   2:     protected void assertHasAtLeastOne( Enumeration enum, Class parent,
   3:             boolean mustHaveAtLeastOne )
   4:         ...
   5:         assertNotNull(
   6:             "Enumeration cannot be null.",
   7:             enum );
   8:         ...
   9:             assertTrue(
  10:                 "Enumeration does not have any contents.",
  11:         ...
  12:             enum.hasMoreElements() );

View Full Code Here
   1:     if (myFlashlightMC == null) {
   2:       Enumeration flashlightEnum = resourceSub.getAddedList();
   3:         ...
   4:       if (debugLevel > 10) System.out.println(name+" FlashlightAllocatorPlugin: execute flashlightEnum.hasMoreElements() "+flashlightEnum.hasMoreElements());
   5:         ...
   6:       while (flashlightEnum.hasMoreElements()) {
   7:         MicroAgent fl = (MicroAgent)flashlightEnum.nextElement();
   8:         ...
   9: 
  10:     Enumeration taskEnum = taskSub.getAddedList();

View Full Code Here
   1: import java.util.StringTokenizer;
   2: import java.util.Enumeration;
   3: import java.util.NoSuchElementException;
   4:         ...
   5:     StringBuffer path = new StringBuffer();
   6:     for (boolean first = true; parser.hasMoreElements(); first = false) {
   7:       if (!first)
   8:         ...
   9: 
  10:   public Enumeration classesInPackage(String packageName) {
  11:     return new ClassPackageEnumeration(this, packageName);
  12:         ...
  13: 
  14: class ClassPackageEnumeration implements Enumeration {

View Full Code Here

nextElement

public E nextElement()
Returns the next element of this enumeration if this enumeration object has at least one more element to provide.
Returns:
the next element of this enumeration.
Throws:
NoSuchElementException - if no more elements exist.
Usages and Demos :

View More Examples of nextElement()
   1: class PrintData {
   2:   static void print(Enumeration e) {
   3:     while(e.hasMoreElements())
   4:         ...
   5:       System.out.println(
   6:         e.nextElement().toString());
   7:   }
   8: }

View Full Code Here
   1: 
   2: import java.util.Enumeration;
   3: import java.util.Hashtable;
   4:         ...
   5:         System.out.println("Known commands: ");
   6:         Enumeration names = commands.elements();
   7:         while (names.hasMoreElements())
   8:         ...
   9:             System.out.println(((Command)
  10:                 names.nextElement()).getClass().getName());
  11:         System.out.println();

View Full Code Here
   1:     out.println("Ulo?ena data relace </h2>");
   2:     Enumeration nazvyRelace = 
   3:       relace.getAttributeNames();
   4:         ...
   5:       String nazev = 
   6:         nazvyRelace.nextElement().toString();
   7:       Object hodnota = relace.getAttribute(nazev);
   8:       out.println(nazev + " = " + hodnota + "<br>");
   9:     }

View Full Code Here
   1: 
   2: import java.util.Enumeration;
   3: 
   4:         ...
   5:                     .getStringValues()
   6:                     .nextElement()
   7:                     .toString();
   8:         ...
   9: 
  10:         Enumeration e = values.getStringValues();
  11:         if (e == null || !e.hasMoreElements())
  12:         ...
  13: 
  14:         return e.nextElement().toString();

View Full Code Here
   1: import java.util.Vector;
   2: import java.util.Enumeration;
   3: 
   4:         ...
   5:     selectionAvailable = val;
   6:     Enumeration e = menuHandlers.elements();
   7:     while(e.hasMoreElements()) {
   8:         ...
   9:         ((TerminalMenuHandler)
  10:          e.nextElement()).updateSelection(selectionAvailable);
  11:     }

View Full Code Here