字典中值的檢索
您可以使用字典類的get()方法檢索特定鍵的值。如果將特定元素的鍵作為此方法的引數傳遞,則它將返回指定鍵的值(作為物件)。如果字典在指定的鍵下不包含任何元素,則返回null。
您可以使用此方法檢索字典中的值。
示例
import java.util.Hashtable;
import java.util.Dictionary;
public class RetrievingElements {
public static void main(String args[]) {
Dictionary dic = new Hashtable();
dic.put("Ram", 94.6);
dic.put("Rahim", 92);
dic.put("Robert", 85);
dic.put("Roja", 93);
dic.put("Raja", 75);
Object ob = dic.get("Ram");
System.out.println("Value of the specified key :"+ ob);
}
}
輸出
Value of the specified key :94.6
廣告