wood burning stoves*
The moose likes Java in General and the fly likes need help copying hashmaps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "need help copying hashmaps" Watch "need help copying hashmaps" New topic
Author

need help copying hashmaps

gino jersey
Greenhorn

Joined: May 24, 2005
Posts: 21
hi all.
i need to have 2 hashmaps so i can write to a log file what the records look like "before" the update.
i have oldHashMap and newHashMap.

my problem is when i update newHashMap, and use OldHashMap to write to the log file, the "new" values are written to the log file.

what's the best way to copy (by value?) the values in oldhashMap to newHashMap.

I tried putAll() but did not work.

thanks.
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
I think you would need to manually iterate through the contents of the old hash map, clone each item, and add each clone to the new hash map.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Look at cloning.
Your problem says that both hashmaps refer to the SAME set of objects. You need to make clones of the objects in the one hashmap and save the clones in the other.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help copying hashmaps
 
Similar Threads
Reading Report parameters from property file and create a method inside a properties
how to compare two Hashmap contents.
create an exception
Getting all data in the consol and dumping it into a text file
Memory size and access