9:13 am - Sunday March 26, 2017

Hash table example program to copy clone value using Clone() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Program Hash Table used to copy clone value using Clone() method

Example Program


import java.util.Hashtable;

public class HashTableClone {

public static void main(String[] args) {

// create two has table

Hashtable htable = new Hashtable();

Hashtable htableclone = new Hashtable();

// put value into table

htable.put(1, "Dog");

htable.put(2, "Cat");

htable.put(3, "Cow");

htable.put(4, "Donkey");

// check table content

System.out.println("Original hashtable content" + htable);

// clone hash table content

htableclone = (Hashtable) htable.clone();

// check content after clone

System.out.println("Clone hashtable content" + htableclone);

}

}

 

 

Output

Original hashtable content{4=Donkey, 3=Cow, 2=Cat, 1=Dog}

Clone hashtable content{4=Donkey, 3=Cow, 2=Cat, 1=Dog}

 

Explanation

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

Declaration:

public Object clone()

.

Overrides:

clone in class Object

 

Returns:

a clone of the hashtable

 

See Also:

Cloneable

BACK

Filed in: Z-A All Java Codes

Comments are closed.