Java Collection Tutorial - Java Hashtable.remove(Object key)








Syntax

Hashtable.remove(Object key) has the following syntax.

public V remove(Object key)

Example

In the following code shows how to use Hashtable.remove(Object key) method.

/* w ww  . jav a 2s .  co m*/
import java.util.Hashtable;

public class Main {
   public static void main(String args[]) {
      // create hash table 
      Hashtable<Integer,String> htable1 = new Hashtable<Integer,String>();      
      
      // put values in table
      htable1.put(1, "A");
      htable1.put(2, "B");
      htable1.put(3, "C");
      htable1.put(4, "from java2s.com");
      
      System.out.println("Initial hash table value: "+htable1);
      
      // remove element at key 3
      htable1.remove(3);
          
      System.out.println("Hash table value after remove: "+htable1);
   }    
}

The code above generates the following result.