Link to home
Start Free TrialLog in
Avatar of InteractiveMind
InteractiveMindFlag for United Kingdom of Great Britain and Northern Ireland

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;
Avatar of InteractiveMind
InteractiveMind
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

The only workaround for this that I can think of, would be:

   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??
ASKER CERTIFIED SOLUTION
Avatar of RomanRega
RomanRega

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cheers