Change key in HashMap

Hi!
Is it possible to change some key in HashMap?
I mean: I've got HashMap<String,Object> and I want to update String (key).
There is one solution possible: to make a temporary object with value, remove the whole row in HashMap and then add a new row <new_String,temporary_value>....
but is there any more elegant way to do this?
thanks

Peter__Lawrey wrote:
McNepp wrote:
Peter__Lawrey wrote:
Keys are generally considered immutable. i.e. they usually don't change. However, what you suggest is a one liner.
map.put(newKey, map.remove(oldKey));
looks alluringly elegant, but adds a mapping from "newKey" to null even if there was no such mapping before.Unless the map doesn't accept nulls in which case it throws an Exception. :-/
Object value = map.remove(oldKey);
if (value != null)
map.put(newKey, value);
And now you've broken it the other way. Maps that do accept null and have an entry for { oldKey --> null } won't get the newKey mapping.
if (map.containsKey(oldKey))
    map.put(newKey, map.remove(oldKey));

Similar Messages

  • So in the last few days I've noticed that pressing my volume change keys actually isn't changing the volume on my macbook pro at all. When I press the volume up or down keys, it makes the recognisable pop sound but stays at the same volume while the squar

    So in the last few days I’ve noticed that pressing my volume change keys actually isn’t changing the volume on my macbook pro at all. When I press the volume up or down keys, it makes the recognisable pop sound but stays at the same volume while the squares go up or down. I mute it but my computer still makes sound. It’s the same with the volume control up the top of the screen, too. I slide it up and down and it doesn’t change the volume at all. The only way I can change the volume is with my speakers or the program I’m in (iTunes, VLC etc). I restarted and it seems to be okay then I go to change it a couple minutes later and it’s back to not working again.
    I’ve checked my settings- the “use all F1, F2, etc. keys as standard fuction keys” is not switched on, and I have tried a suggestion of moving the com.apple.systempreferences.plist file out of the library and onto the desktop and restarting and neither of those seem to make any difference whatsoever. I’ve tried to find online forums but the only suggestions I found were those two and they didn’t work.
    I’m just annoyed because I usually have the worst luck with technology but my macbook had been going strong and I got it because of the apparent lack of things that could go wrong, but of course even if there is one thing that could go wrong it will happen to me.
    Please help!

    You migh give resetting your NVRAM a try:
    http://support.apple.com/kb/ht1379

  • Is there somebody out there to shed some light on this? Change keys, tempo in Soundtrack Pro greyed out?

    From the amount of posted unanswered questions like mine one should be able to see that there are more than a few people confused about the greyed out "Change keys, tempo in Soundtrack Pro" (and for that matter in Apple Loops Utility, Logic, GarageBand)! What does it take to help out the less adept budding beginners? Please don't post read the manual or search for... we all know you can spend days with no results. There is nothing better than a friendly person (wizard) who knows and has done it all, giving clear step by step instructions. Please lay it out for us lesser brains. Thank you so much for your time and patience.

    rs = stmt.executeQuery("SELECT gender FROM gymuser WHERE Username= 'userName' ");
    in this line i think there is some error put it like this
    rs = stmt.executeQuery("SELECT gender FROM gymuser WHERE Username= '"+userName+"' ");
    Try to put some SOPs in between, so that u can check in logs(if using tomcat)where u r making mistake.

  • Garage Band '11, version 6.0.5 will not change key after new project is started

    Garage Band '11 version 6.0.5:  Cannot change key after new project is started.
    It has always worked ok prior to this. And I have had other issues. How do I reinstall Garage Band '11?
    I have looked in downloads, but can'ty find any download file. I had upgraded to Mac OSX 10.6.8 couple years back, which included
    Garage Band '11, a new ITunes & new IPhoto.

    Before reinstalling I'd try HangTime's fix for "oddball" problems and delete the User preferences and repair permissions, see the FAQ:
    http://www.bulletsandbones.com/GB/FAQPages/OddBallProbs.html
    The GarageBand 6.0.5 update is here: 
    GarageBand 6.0.5
    If you want to reinstall, install again the GaragaBand application from your installation disk and then upgrade again to 6.05 using the link above or Software update from the Apple Menu.
    Regards
    Léonie

  • Changing key in Logic Loops...

    I'm able to change key in the loops, but once I drag that loop, in it's changed key, to my track, the sound reverts back to the original key. How do I record the loop in the changed key? Thanks!

    Select the region and choose Region > Bounce in place
    or solo the track and set the cycle area to fit the region (apple loop) and choose file > Bounce

  • Can we change key field values in table maintenance

    Hi,
      I have created Z-table and table maintenance for the same...
    In table maintenance..Can we change key field values??
    Is there any posibility????
    Rayudu

    you can do it in this way.
    open sm30->tablname->edit
    snow select the row(s)->copy->change the keyfield values-back->save.
    no in that sm30, select records with old primary key and delete->save.
    so you got all field similar for those record under modification, only the key field changed.

  • Linksys WET54G connected to HP 420 AP change key types

    Linksys WET54G connected to HP 420 AP change key types. it works for a day or so and suddenly it change the key-type from WPA-TKIP to WEP. communication fails of course. Restart the units will make it to work again sometimes you will have to restart it several times. some ide what the problem may be ?

    Sorry we don't have an answer for you. Recommend you try the Linksys by Cisco forums at http://forums.linksysbycisco.com. Hopefully you find the solution there.

  • Change Key Fig. on a aggregated level alowed ?

    Hello Gurus,
    is it possible to change Key Figures on a aggregated Level ?
    THNX

    Hi.
    What do you exactly mean ?
    You can add/remove KF from aggregation levels (KF should exist in infocube).
    You cant change KF in aggr level (I mean you can't change length or other properties of IO via aggr level).
    Regards.

  • Duplicate keys for HashMap

    Hi,
    I have a class I created, call it MyClass. It looks like this:
    public String myString;
    public final String toString() {
        return myString;
    public boolean equals(MyClass mc) {
        return (mc != null && myString.equalsIgnoreCase(mc.toString()));
    }When I use objects of type MyClass as the keys to a HashMap when doing a put(), duplicate keys seem to be allowed. And when I query, knowing that I have an entry for a key, I get null. However, when I change my get() and put() to use MyClass.toString() as the key, everything works fine.
    It seems to me that the JVM must be assuming that different instances of objects of type MyClass are different and thus a new key+value is created when "putting" instead of the old value being overwritten. But MyClass has an equals() method, so when putting, why doesn't it tell the JVM that the key already exists?
    Thanks,
    Jeff

    True, I missed that.
    Were you thinking that the HashMap is going to use the equals you provide that takes MyClass as an arg? It won't. It uses the one that takes Object, which means you'll be using Object's equals, which compares references, so no MyClass can ever be equal to another.
    You need to override equals (with the Object argument) and override hashCode.

  • Changing key of a loop?

    Can I change the key of a loop (say, from A to D) to accompany tune, so that the same loop is used in the track in different keys?

    Yes, you can.
    Add a new copy of your loop to the track in the timeline, select it, and in the track editor enable "follow tempo and pitch" (for real instrument loops) and adjust the pitch slider. You will see the transposition in the lower left corner of the loop (in half note steps).
    Regards
    Léonie

  • Changing key figure values in DSO/Cube

    Experts,
    I have a DSO and a Cube and the data has been already loaded in to a amount Key Figure. By default it is 2 decimal places. I want to change the decimals to 7. I cannot delete data from the cube or the DSO.
    Can you please suggest some ideas to do this.
    I came accross this note 579342 which talks about realigning this but as I have not implemented this before, I wanted to get your thoughts on if this is safe to do.
    Thanks
    Yashu raj

    Hi Yashu,
    I did this with using system message board and I put message on EP tooo.
    So you do a small R&D. Run this report and let me know too if amount data is reflecting in the cube or not.
    Logically it should not but have a try?
    Regards,
    Mahesh

  • Unable to Change Key Figure in DP

    Hello Experts,
    I am facing an error in Demand Planning.  There is an existing Key figure in which I need to change the Type/Data type from Number to Quantity wherein it is showing Grey(uneditable) even in Change mode.  The other tabs like Aggregation, Additional Properties are showing as editable.
    Could you please provide how to modify this Type/Data type field in the key figure.  I would appreciate your quick turnover based on which I need to decide on my solutioning approach to my client.
    Thanks in advance.
    Regards
    R. Senthil Mareeswaran.

    Hi Senthil,
    Try to delete the existing data in your key figure. and then try to change the key figure type. However in SNP i checked that keyfigure type can be changed. Are using RSA1 for this?
    Thanks,
    Satyajit

  • How to get a list corresponding to each key in hashmap

    hi all
    in hash map we can put key value pairs ... but what if i want to get a list of values coresponding to each unique key ..
    ... can we do it by storing a list Object corresponding each key in a HashMap ... is this the best way out ??
    For example in a chat server ... i want to mainitain a list of users corresponding to each room (the key ) in a HashMAp .. so the corresponding operations would be adding and deleting users as and when they login / logout .. getting a list of alll users in a particular room .. etc

    Actually i am looking forward for something like
    I may b wrong in syntax .. just doing it to give you a clear picture...
    HashMap h = new HashMap();
    // now suppose chat rooms are "billing","faq"
    //adding users for room billing
    h.add("billing","John");
    h.add("billing","Mr. A");
    h.add("billing","Mr. B");
    //adding for room faq
    h.add("faq","Mr. C");
    h.add("faq","Mr. D");
    // now i want all users of billing
    List l = h.get("billing");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Logic Pro X loops not changing key when imported

    Hi everyone,
    I am a newbie and I have found a problem when importing Audio files (Loops) from the Loop section into a song I am working on in the project area. When I do this instead of the imported loop changing its key to fit in with the Key signature of the song I am writing it stays in its own key. For example the song I am writing is in C Major and the imported Loop is in A sharp. I have been told that when you import this loop by dragging and dropping into the project area that it should automatically change to the key of the project which of course is C Major but this is not happening and I do not know why?
    When I then try to add other instruments in the key of C Major for example a bassline I discover that playing a bass line in C Major is completely out of the tune with the imported loop which is in A sharp. When I play notes from the A sharp scale over this imported loop it is perfectly in tune so its clear that for some reason the loop is not changing its key when its imported.
    Any solutions for this would be greatfully received.

  • Need help to map a key in hashmap

    hi guys,
    I want to find a value from hashmap.
    But the key should be matched a regex.
    I want something like...
    hashmap.contains(regex key)Thanks in advance...

    Dhaval.Yoganandi wrote:
    But I dont want to iterate through all the keys...Then stop as soon as you've found one.
    Edit: Why don't you want to iterate through all the keys?
    is there any other solution ? Otherwise I've to go for iteration..Not really. You could store your data in a different data structure that is more useful for searching for regex, but all solutions will come down to linearly searching through all (or some) elements and checking the regex.
    If you don't really need the full power of a regex, then you might find a better datastructure, for example using a Trie for prefix-matching.

Maybe you are looking for

  • Problems changing colour using Graphics class in java.awt

    Hi, The problem only happens when more than two images are on a panel. In this case, I have to strings that are drawn. The first drawn string is called "A" the second drawn string is called "B". However, when i change the colour of "B" to let's say R

  • Macbook 5,2 S-ATA Controller 1,5 GB or 3,0 GB throughput?

    Kann mein Macbook 5,2 auch SSD Platten mit 3,0GB betreiben oder laufen hier nur 1,5GB Durchsatz.

  • Update/Insert key matching

    I've got a table in OWB that has a surrogate key as the unique key and the natural key (matching the source data) as part of the orginal key and a lookup value that's part of a dimension in OWB. I'm trying to figure out how to get OWB to match data t

  • HELP - MRP and Stock in subcontractor!

    Hello SAP gurus, I have a little problem with MRP and the stock in the subcontractor. This is the scenario: PLANT..........MRP ELEMENT..........QUANTITY 2100.............Free Stock..................500UN 2100.............Reser........................

  • Just upgraded to 10.4.7 by Software Update - Avid dongle not working

    I upgraded as I always do thru the Software Update - so it's the combo. Never really had problems like this before. I had to reboot many times to get the desktop to come up - ran disk utilitly and fixed permissions and disk - no many errors. All fixe