java.util.Hashtable.clone() Method
Advertisements
Description
The clone() method is used to create a shallow copy of this hashtable.
Declaration
Following is the declaration for java.util.Hashtable.clone() method.
public Object clone()
Parameters
NA
Return Value
The method call returns a clone of the hashtable.
Exception
NA
Example
The following example shows the usage of java.util.Hashtable.clone()
package com.tutorialspoint;
import java.util.*;
public class HashTableDemo {
public static void main(String args[]) {
// create two hash tables
Hashtable htable = new Hashtable();
Hashtable htableclone = new Hashtable();
// put values into the table
htable.put(1, "A");
htable.put(2, "B");
htable.put(3, "C");
htable.put(4, "D");
// 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);
}
}
Let us compile and run the above program, this will produce the following result.
Original hash table content: {4=D, 3=C, 2=B, 1=A}
Clone table content: {4=D, 3=C, 2=B, 1=A}