您的位置:首页 > 移动开发 > Objective-C

java.util.Hashtable.containsKey(Object key)方法实例

2013-12-17 07:30 561 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: