Posted By:
Anonymous
Posted On:
Tuesday, January 2, 2007 08:20 AM
I assume you want to update the (key, value) pair to (key2, value) where key != key2.
First of all, I don't know why you want to do this, but let's assume you have a good reason.
What I would do is simply remove(key) and put(key2, value). That way your first pair is removed and the second pair added.
Some things you may want to think about when using this:
- If your map is ordered (e.g. LinkedHashMap), then the entry drops from its original position to the end (assuming key2 did not yet occur in the map, otherwise see the next point:)
- If there is already an entry for key2, its value will be overwritten by this operation.
If this is as intended, go ahead and change keys in your map; if you encountered an *oops* here, you may want to think about why you think you need this a little longer.