• Java 資料結構教程

雜湊表中值的檢索



您可以使用 get() 方法檢索特定鍵的值。如果您將特定元素的鍵作為此方法的引數傳遞,它將返回指定鍵的值(作為物件)。如果雜湊表在指定的鍵下不包含任何元素,則返回 null。

您可以使用此方法檢索雜湊表中的值。

示例

import java.util.Hashtable;
public class RetrievingElements {
   public static void main(String args[]) {
      Hashtable hashTable = new Hashtable();
      hashTable.put("Ram", 94.6);
      hashTable.put("Rahim", 92);
      hashTable.put("Robert", 85);
      hashTable.put("Roja", 93);
      hashTable.put("Raja", 75);      
      
      Object ob = hashTable.get("Ram");
      System.out.println("Value of the specified key :"+ ob);            
   }
}

輸出

Value of the specified key :94.6
廣告
© . All rights reserved.