Java Collection Tutorial - Java Hashtable.clear()








Syntax

Hashtable.clear() has the following syntax.

public void clear()

Example

In the following code shows how to use Hashtable.clear() method.

/*  www.  j  ava 2 s. c  o m*/


import java.util.Hashtable;

public class Main {
   public static void main(String args[]) {

      Hashtable<Integer, String> htable = new Hashtable<Integer, String>();

      // put values into the table
      htable.put(1, "A");
      htable.put(2, "B");
      htable.put(3, "C");
      htable.put(4, "from java2s.com");
      
      // check table content
      System.out.println("Hash table content: "+htable);
      
      // clear the table
      htable.clear();
      
      // check content after clear
      System.out.println("Hash table content after clear: "+htable);      
   }    
}

The code above generates the following result.