Java.util.Dictionary.get() 方法
描述
java.util.Dictionary.get(Object key) 方法返回字典中给定键上的值。
声明
以下是 java.util.Dictionary.get() 方法的声明
public abstract V get(Object key)
参数
key − 这个字典中的一个键。 如果键未映射到任何值,则可以为 null。
返回值
此方法返回此字典中键映射到的值。
异常
NA
示例
下面的例子展示了 java.util.Dictionary.get() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class DictionaryDemo {
public static void main(String[] args) {
// create a new hashtable
Dictionary dict = new Hashtable();
// add elements in the hashtable
dict.put("1", "Chocolate");
dict.put("2", "Cocoa");
dict.put("6", "Coffee");
// returns the elements associated with the key
System.out.println(dict.get("6"));
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
Coffee

