This week's book giveaway is in the JavaScript forum.
We're giving away four copies of JavaScript Promises Essentials and have Rami Sarieddine on-line!
See this thread for details.
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 JavaScript Promises Essentials this week in the JavaScript 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: 690
    
    1
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