Java Collection Tutorial - Java Dictionary.elements()








Syntax

Dictionary.elements() has the following syntax.

public abstract Enumeration <V> elements()

Example

In the following code shows how to use Dictionary.elements() method.

/* w ww. java2  s. com*/

import java.util.*;

public class Main {

   public static void main(String[] args) {

      Dictionary d = new Hashtable();

      // add 2 elements
      d.put(1, "Cocoa");
      d.put(4, "from java2s.com" + "Bar");
      System.out.println("1 is " + d.get(1));
      System.out.println("4 is " + d.get(4));

      // generates a series of elements, one at a time
      for (Enumeration e = d.elements(); e.hasMoreElements();) {
         System.out.println(e.nextElement());
      }
   }
}

The code above generates the following result.