目录

abstract Enumeration<K> keys()

描述 (Description)

java.util.Dictionary.keys()方法获取此字典中键的枚举。

声明 (Declaration)

以下是java.util.Dictionary.keys()方法的声明

public abstract Enumeration<K> keys()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回此字典中键的枚举。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.Dictionary.keys()方法的用法。

package com.iowiki;
import java.util.*;
public class DictionaryDemo {
   public static void main(String[] args) {
      // create a new hashtable
      Dictionary d = new Hashtable();
      // add some elements
      d.put("1", "Chocolate");
      d.put("2", "Cocoa");
      d.put("5", "Coffee");
      // return an enumeration of the keys from this dictionary.
      for (Enumeration e = d.keys(); e.hasMoreElements();) {
         System.out.println(e.nextElement());
      }
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

5
2
1
↑回到顶部↑
WIKI教程 @2018