remove(Object key)%uA0方法用于从该散列表中删除键(和其对应的值)。
声明
Following is the declaration for%uA0java.util.Hashtable.remove()%uA0method.
public V remove(Object key)
参数
-
key--这是一个需要被删除的键。
返回值
方法调用返回到该键存在映射此哈希表中,返回null,如果该键没有映射值。
异常
-
NullPointerException--%uA0如果指定键为null,这将被抛出。
例子
下面的例子显示java.util.Hashtable.remove()方法的使用
package com.yiibai import java.util.* public class HashTableDemo { public static void main(String args[]) { // create hash table Hashtable htable = new Hashtable(3) // populate the table htable.put(1, "TP") htable.put(2, "IS") htable.put(3, "THE") htable.put(4, "BEST") htable.put(5, "TUTORIAL") System.out.println("Initial hash table value: "+htable) // remove element at key 3 htable.remove(3) System.out.println("Hash table value after remove: "+htable) } }
现在编译和运行上面的代码示例,将产生以下结果。
Initial hash table value: {5=TUTORIAL, 4=BEST, 3=THE, 2=IS, 1=TP} Hash table value after remove: {5=TUTORIAL, 4=BEST, 2=IS, 1=TP}