InteractiveMind
asked on
Rename Key in HashMap
Hello,
I have a a HashMap, for the sake of this question, we'll say that it's like the following:
HashMap map = new HashMap( 5, 0.75F );
map.put( "KeyName", new JFrame("Example") );
I somehow, need to be able to rename the key "KeyName" to something else.. is there a way to change the 'Key' of an element in a HashMap??
Regards;
I have a a HashMap, for the sake of this question, we'll say that it's like the following:
HashMap map = new HashMap( 5, 0.75F );
map.put( "KeyName", new JFrame("Example") );
I somehow, need to be able to rename the key "KeyName" to something else.. is there a way to change the 'Key' of an element in a HashMap??
Regards;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers
ASKER
HashMap map = new HashMap( 5, 0.75F );
map.put( "KeyName", new JFrame("Example") );
...
Object temp = map.get( "KeyName" );
map.remove( "KeyName" );
map.put( "NewKeyName", temp );
However, this way doesn't seem very efficient.. :o\
Any other ideas??