0

I had a HashMap and I used the clone function to make a deep copy. But I switched this to a WeakHashMap to try out some memory management.

I still want to do this clone function but it isn't part of the methods in WeakHashMap. How do I efficiently clone a WeakHashMap into another one? I suppose I could do a loop, adding keys and checking for existing keys etc, but I'm not sure if that's the best way.

CQM
  • 42,592
  • 75
  • 224
  • 366
  • 1
    The best way is the way you do in the next 5 minutes ... unless performance analysis shows it is too slow. –  Dec 10 '11 at 22:00

1 Answers1

1

As you have to copy all the elements contained in your map, a for loop is required in order to sequentially visit all key and value pairs.

GETah
  • 20,922
  • 7
  • 61
  • 103