Java Hashtable.clone()

Syntax

Hashtable.clone() has the following syntax.

public Object clone()

Example

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


//from  w  ww . j a v a 2s .com
import java.util.Hashtable;

public class Main {
   public static void main(String args[]) {
      // create two hash tables 
      Hashtable<Integer, String> htableclone = new Hashtable<Integer, String>();
      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("Original hash table content: "+htable);
      
      // clone hash table
      htableclone=(Hashtable)htable.clone();
      
      // check content after clone
      System.out.println("Clone table content: "+htableclone);      
   }    
}

The code above generates the following result.