Java Collection Tutorial - Java Dictionary.elements()


Dictionary.elements() has the following syntax.

public abstract Enumeration <V> elements()


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" + "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();) {

The code above generates the following result.