http://www.yiibai.com/java/util/ashtable_containskey.html
描述
The containsKey(Object key) method is used to test if the specified object is a key in this hashtable.
声明
Following is the declaration for java.util.Hashtable.containsKey() method.
public boolean containsKey(Object key)
参数
-
key--This is the a key to be searched.
返回值
The method call returns true if and only if the specified object is a key in this hashtable.
异常
-
NullPointerException--This is thrown if the key is null.
以下例子将告诉你如何使用 java.util.Hashtable.containsKey()
package yiibai.com; import java.util.*; public class HashTableDemo { public static void main(String args[]) { // create hash table Hashtable htable = new Hashtable(); // put values into the table htable.put(1, "A"); htable.put(2, "B"); htable.put(3, "C"); htable.put(4, "D"); // check if table contains key "3" boolean isavailable=htable.containsKey(3); // display search result System.out.println("Hash table contains key '3': "+isavailable); } }
Let us compile and run the above program, this will produce the following result.
Hash table contains key '3': true