Question about clone a Hashtable
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   George_Lin
Posted On:   Sunday, May 15, 2005 05:44 AM

Hello everyone, I want to clone the content of a Hashtable (its keys, its values and its key-value relationship). But I have found that the clone method can not completely clone a Hashtable, as is mentioned in the description of clone method of Java API Specification, 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. I am wondering what is the efficient and effective approach of cloning a Hashtable, including the clone of its keys, its values and its key-value relationship. Thanks in advance, George    More>>
			
Hello everyone,


I want to clone the content of a Hashtable (its keys, its
values and its key-value relationship). But I have found
that the clone method can not completely clone a Hashtable,
as is mentioned in the description of clone method of Java
API Specification,

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.

I am wondering what is the efficient and effective approach
of cloning a Hashtable, including the clone of its keys,
its values and its key-value relationship.


Thanks in advance,
George
   <<Less

Re: Question about clone a Hashtable

Posted By:   Stephen_Ostermiller  
Posted On:   Sunday, May 15, 2005 09:53 PM

I'd create a new hash table (the same size as the old one), enumerate the old hash table, and clone the key and values one at the time as I add them to the new hash table.


Maybe there is a better way, but I can't think of it.

About | Sitemap | Contact