Ikes Ikes - 1 year ago 153
Java Question

Is it possible to rename a Hashmap key?

I'm looking for a way to rename a Hashmap key, but i don't know if it's possible in Java.

Answer Source

Try to remove the element and put it again with the new name. Assuming the keys in your map are String, it could be achieved that way:

Object obj = map.remove("oldKey");
map.put("newKey", obj);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download