Hashtable clone Example
Hashtable class clone example. This example shows you how to use clone method.
Hashtable class clone method example.Creates a shallow copy of this hashtable. All the structure of the hashtable itself is copied, but the keys and values are not cloned. This is a relatively expensive operation.
Syntax - public Object clone()
Here is the code
/**
* @ # Clone.java
* A class repersenting use to clone method
* of HashMap class in java.util package
* version 19 May 2008
* author Rose India
*/
import java.util.*;
public class Clone {
public static void main(String args[]) {
Hashtable table = new Hashtable();
//insert maps into table
table.put(1, "A");
table.put(2, "B");
table.put(3, "C");
table.put(4, "D");
System.out.println("table :" + table);
//Create clone of table
Hashtable table1=(Hashtable)table.clone();
System.out.println("table1 :" + table1);
}
} |
Output
table :{4=D, 3=C, 2=B, 1=A}
table1 :{4=D, 3=C, 2=B, 1=A} |
|