Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help copying hashmaps

 
gino jersey
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Norm Radder
Ranch Hand
Pie
Posts: 1031
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic