集册 Java实例教程 检查哈希表中是否存在特定密钥

检查哈希表中是否存在特定密钥

欢马劈雪     最近更新时间:2020-01-02 10:19:05

398
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
检查特定的密钥是否存在于哈希表中

 

import java.util.Hashtable;/**来 自 时   代    Java - nowjava.com**/

 

public class Main {

  public static void main(String[] args) {

    Hashtable ht = new Hashtable();

   

    ht.put("1","One");

    ht.put("2","Two");

    ht.put("3","Three");

   

    boolean blnExists = ht.containsKey("2");

    System.out.println("2 exists in Hashtable ? : " + blnExists);

  }

}