Java.util.Dictionary.elements() 方法


Java.util.Dictionary.elements() 方法

package com.codingdict;

import java.util.*;

public class DictionaryDemo {
   public static void main(String[] args) {

      // create a new hashtable
      Dictionary d = new Hashtable();

      // add 2 elements
      d.put(1, "Cocoa");
      d.put(4, "Chocolate" + "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());
      }
   }
}