Java Collection Tutorial - Java Dictionary.keys()


Dictionary.keys() has the following syntax.

public abstract Enumeration <K> keys()


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

import java.util.*;
// ww w  . ja v a 2 s . c o  m
public class Main {

   public static void main(String[] args) {
      Dictionary d = new Hashtable();
      // add some elements
      d.put("1", "from");
      d.put("2", "Cocoa");
      d.put("5", "Coffee");
      // return an enumeration of the keys from this dictionary.
      for (Enumeration e = d.keys(); e.hasMoreElements();) {

The code above generates the following result.