TreeMap class and message not understood issues - help please

Can anyone help with this one please?
The code is the start of a Map interface/TreeMap class to hold names as keys and addresses as values (both Strings).
I think the instance variable and the constructor are correct, but the addAddress method throws an error
Semantic error: Message addAddress( java.lang.String, java.lang.String ) not understood by class'java.util.TreeMap'.
I can only guess that I've overlooked something quite simple? The line at the end of the code should read
"Replaced "old address" with "new address" for "new name" and this should only display if the key already exists in the Map,
hence the if statement. The keys and values have been declared as Objects for future flexibility. Sorry if this is all blatantly obvious.
Also if I wanted to test this code and create an instance of the Addressbook class, what should my code look like?
Many thanks.
{code}import java.util.*;
public class Addressbook
private static Map<Object, Object> addresses;
public Addressbook()
super();
this.addresses = new TreeMap<Object, Object>();
public static void addAddress(String name, String address)
if (addresses.containsKey(name))
addresses.put(name, address);
System.out.println("Replacing " + addresses.remove(name) + " with "
+ addresses.get(name) + " for " + name);
else
addresses.put(name, address);
{code}

If you're only going to store Strings in the Map, make sure you are specifying them as generics so that all operations return Strings by default.
You don't need to use contains if you are going to replace a map value. The old value will be returned when you place the new one in. Should be quicker, since you're not searching for the same key twice.
Do not refer to a static variable with this. it become confusing and could result in bugs. That said use static sparingly.
The AddressBook should probably be an instance and all the variables and methods should be instance variable and methods.
I don't know your requirements however so I'll leave this as a suggestion.
import java.util.*;
public class AddressBook {
   private static Map<String, String> addresses = new TreeMap<String, String>();
   public static void addAddress(String name, String address) {
      String oldAddress = addresses.put(name, address);
      if(oldAddress != null) {
            System.out.printf("Replacing %s with %s for %s%n", oldAddress, address, name);
    public static void main(String[] args) {
        addAddress("me", "123");
        addAddress("me", "321");
}Brushfire,

Similar Messages

  • I am trying to update i Tunes to new version i get a message saying iTunes has an invalid signature and will not install.Any help please.

    I am trying to update iTunes to new version .
    When it goes to install i get a message saying iTunes has an invalid signature and will not install.
    Any help please.

    Go directly to Apple link to download
    http://support.apple.com/kb/DL1426
    Select "Save" instead of "Run".  Once downloaded, double click the iTunesetup.exe to install.

  • IMessage and FaceTime not working, Urgent Help please!!!

    Hi guys,
    Need help urgently, my iMessage and FaceTime are both not working on my Macbook Pro.
    The iMessage gives giving this message "Could not sign in. Please check your network connection and try again.", while FaceTime just simply cannot login.
    Please help!!!

    This could be a complicated problem to solve, as there are many possible causes for it. Test after taking each of the following steps that you haven't already tried. Back up all data before making any changes.
    Before proceeding, test on another network, if possible. That could be a public Wi-Fi hotspot, if your computer is portable, or a cellular network if you have a mobile device that can share its Internet connection. If you find that iMessage works on the other network, the problem is in your network or at your ISP, not in your computer.
    Step 1
    Check the status of the service. If the service is down, wait tor it to come back up. There may be a localized outage, even if the status indicator is green.
    Step 2
    Sign out of iMessage and FaceTime on all your Apple devices. Log out and log back in. Try again to sign in.
    Step 3
    Restart your router and your broadband device, if they're separate. You may have to skip this step if you don't control those devices.
    Step 4
    From the menu bar, select
               ▹ About This Mac
    Below the "OS X" legend in the window that opens, the OS version appears. Click the version line twice to display the serial number. If the number is missing or invalid according to this web form, take the machine to an Apple Store or other authorized service center to have the problem corrected.
    Step 5
    Take the steps suggested in this support article. If you don't understand some of the steps or can't carry them out, ask for guidance.
    Step 6
    From the menu bar, select
               ▹ System Preferences... ▹ Network
    If the preference pane is locked, click the lock icon in the lower left corner and enter your password to unlock it. Then click the Advanced button and select the Proxies tab. If the box marked SOCKS Proxy is checked, uncheck it. You don’t need to change any other settings in the window. Click OK and then Apply. Test.
    The result may be that you can't connect to the Internet at all. Revert the change if that happens, or if iMessage still doesn't work. Remember that you must Apply any changes you make in the preference pane before they take effect.
    Step 7
    Select from the menu bar
               ▹ System Preferences… ▹ Flash Player ▹ Storage
    and click
              Block all sites from storing information on this computer
    Close the preference pane.
    Step 8
    Make sure you know the ID and password you use with iMessage. Launch the Keychain Access application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad and start typing the name.
    Use the search box in the toolbar of the Keychain Access window to find and delete all items with "iMessage" or "com.apple.idms" in the name. Log out and log back in.
    Step 9
    Enable guest logins* and log in as Guest. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your personal files or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    If iMessage worked in the guest account, stop here and post your results.
    Step 10
    Start up in safe mode and log in to the account with the problem. You must hold down the shift key twice: once when you start up, and again when you log in.
    Note: If FileVault is enabled in OS X 10.9 or earlier, or if a firmware password is set, or if the startup volume is a Fusion Drive or a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to start and run than normal, with limited graphics performance, and some things won’t work at all, including sound outputand Wi-Fi on certain models. The next normal startup may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. After testing, restart as usual (i.e., not in safe mode) and test again.
    If iMessage worked in safe mode, but still doesn't work when you restart in "normal" mode, stop here and post your results.
    Step 11
    Triple-click anywhere in the line below on this page to select it:
    /Library/Preferences/com.apple.apsd.plist
    Right-click or control-click the highlighted line and select
              Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item selected. Move the selected item to the Trash. You may be prompted for your administrator login password. Restart the computer and empty the Trash.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
              Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.
    Step 12
    Reset the NVRAM.
    Step 13
    Reset the System Management Controller (SMC).
    Step 14
    Reinstall OS X.
    Step 15
    If none of the above steps resolves the issue, make a "Genius" appointment at an Apple Store, or contact Apple Support. When you set up a support call, select "Apple ID" as the product you need help with, not the hardware model. That way, if you're not under AppleCare, you may be able to talk your way out of being charged for the call.

  • TS1541 I tried importing email addresses from gmail and now my address book is locked up and will not work. Help please.

    I tried importing email addresses from gmail and now my address book is locked up and will not work. Do I need to delete my address book software and reinstall? If so, what is the proper way to do this? New to Macbook software. I have tried several things and nothing has helped. I have backed up photos, movies, etc. My addresses are on my iphone so I can sync them later right if I loose my data?
    Thanks for your time and expertise,
    T.

    You can probably resolve this by removing some Address Book preference files rather than deleting your Address Book application.
    First turn off Synchronize in Address Book Preferences if you can.
    Next restart Address Book and try to export everything to your Desktop.
    I have had a play and found my Address Book preference files. In the following ~/Library is the Library within your Home folder. Any numerals may differ on your Mac. Quit Address Book before doing anything with these.
    1 - Display details and things set in Address Book Preferences
    ~/Library/Preferences/com.apple.AddressBook.plist
    2 - Has no data - not sure what this does
    ~/Library/Preferences/com.apple.AddressBook.abd.plist
    3 - Has last sync date - may have more if I used sync
    ~/Library/Preferences/ByHost/com.apple.AddressBook.sync.000393735c06.plist
    4 - My contact details
    /Library/Preferences/AddressBookMe.plist
    5 - Individual addresses and groups stored as separate files within:
    ~/Library/Application Support/AddressBook/Metadata
    6 - All of these addresses are are also in this single database:
    ~/Library/Application Support/AddressBook/AddressBook-v22.abcddb
    If you wish to remove all addresses drag both 5 & 6 to your Desktop.
    If you wish to reset preferences drag 1 your Desktop.
    Removing 3 may resolve sync issues but I am unable to test this.
    If you wish to reset everything drag all except 4 to your desktop.
    Apple has an interesting page at: http://support.apple.com/kb/TS2481
    I hope this helps.

  • Hi..i have a problem with adobe muse..i can t open it.i double click and is not opening..help please

    hello!!i have a problem with adobe muse..i can t open it.i double click and is not opening..i don t think it s a problem from computer because adobe is the only i can t open ..a few hours ago i could open,and now i can t anymore..please help

    Can you open the application from programs list ?
    Also, please verify if the application is installed correctly and if not then probably a re-installation would be required.
    For Immediate support its always recommended to join our Live chat team.
    Thanks,
    Sanjit

  • Elements 10 not working and uninstall not working either help please?

    Elements 10 does not work and I have tried to uninstall it with the intention of re-installing.   When I press un-install it tells me it is still uninstalling or changing the program but this has been happening for three hours?  Windows installer is saying 'cancelling' the same for two hours.  I am stuck please help.  Many thanks in advance from a well qualified luddite!

    Update - I am manually un-installing because as I can't get photoshop to work - (it says it is scanning for updated and never stops -)  I assume it is corrupt.  I have selected it and then uninstalled - had no further options offered to me and now it is saying ' please wait until the current program is finished unistalling or being changed'  I am totally confused.  Now I am getting the message 'Install server not responding'  Please help.

  • Since iOS7 update my snapchat iMessage and FaceTime not working. Help please!

    I updated my iPhone 4S a few weeks ago. Since then I can't use iMessage and get no messages from those who do have iMessage. My FaceTime will not let me sign in. And my snapchat gets a popup that so t go away. Also my phone freezes more. What can I do to get my phone back to "awesomeness?" Please help.

    stedman1 is a really smart guy, but he is not all seeing.
    Nobody knows how long it will be down. We are just other iPad users like you and are no privvy to any more information than you are.

  • Ipod nano does not connect to itunes and will not launch. Help please?

    I was about to download some tracks onto my sons ipod nano when got the update message. I wish I had ignored it as my days have been taken over with scouring support, discussions and other sources to get itunes to launch. I have deleted, stopped, repaired and changed files. Nothing happens. No error message. Get the hour glass for couple of secs, thats all. Quicktime launches fine (also updated). Windows sees ipod hardware. What is going on? Granny is giving son an itunes gift card. As I have never allowed him to download tunes he is going to be thrilled............. except he can't use it!!!! I've spent way to many hours trying to find solution. Can anyone help me? Please?

    Sometimes iPod simply won't work off certain USB hubs. If it works directly off the computer, then continue to use that. Your only other choice is to try out other hubs until you find one that works. Is it a powered hub?
    Patrick

  • Can not turn i pad on, i did hard reset and still not working ? help please

    can not turn i pad 2 on , I did try the hard reset, no luck. help please

    Probably depends on how long you've had it. I don't know what Best Buy's returns/repairs policies are, and whether you're within their exchange period. You could try contacting them

  • I have a macbook pro and F3 for launchpad and I tried to restore it and its not working. Help please, what should I do?

    Plase help

    Not sure what you are asking here.
    Are you saying that pressing F3 no longer brings up Launchpad?
    If so check System Preferences > Keyboard > Keyboard Shortcuts
    Follow the instructions at the top of the box. (Double-click "Show Launchpad" and then press the F3 key on your keyboard.)
    Should start working again.
    Also, make sure that System Preferences > Keyboard > Keyboard "Use All F1, F2, etc, keys as standard function keys" is UNchecked.

  • I have a 27" thunderbolt display NOT the iMac, and I'm trying to connect my xbox 360 to it via the Belkin AV360. I plug everything in and it does not work? I check all the power cables and and connections and still not he issue. Iv'e tried C-F2 also. Help

    I have a 27" thunderbolt display NOT the iMac, and I'm trying to connect my xbox 360 to it via the Belkin AV360. I plug everything in and it does not work? I check all the power cables and and connections and still not he issue. Iv'e tried C-F2 also. has anyone used this devive (AV360) on there own 27" thunderbolt display (not the imac) and gotten it to work? If so I'd appreciate the help.

    There are multiple reasons that lead to issue. You should read the troubleshooting guide to get the right solution to solve the issue: iPhone, iPad, or iPod touch not recognized in iTunes for Windows - Apple Support

  • Recently i upgrade my iPad2 to 7.1(11D167) and now the wifi connection is very weak, I am not sure if it is a hardware or software issue, help please!

    Recently i upgrade my iPad2 to 7.1(11D167) and now the wifi connection is very weak, I am not sure if it is a hardware or software issue, help please!

    I am not sure, I have full signal on my iphone 5  and just 1 dot on my ipad, tomorrow I will test connection with other router and network, I thank you for your help and I will tell you the test result when done

  • I recently purchased a MacBook Air and was told by Apple that Keynote and Pages were compatible with MS Applications.. I have since tried to open a Powerpoint Presentation but it comes up with an error message and is not right. Help!

    I recently purchased a MacBook Air and was told by Apple that Keynote and Pages were compatible with MS Applications.. I have since tried to open a Powerpoint Presentation but it comes up with an error message and is not right. Help!

    If there are fonts, transitions, builds, video or audio in the PowerPoint file that are not compatible with Keynote, it will either prevent the presentation opening or Keynote will substitute the settings causing playback changes.
    I use Open Office to play and open any PowerPoint files sent to me, they play exactly as in PowerPoint.
    Open Office is free, you can download it here:
    Open Office for Mac

  • Hi when i use treeMap class and if i exit the program

    hi
    hi when i use treeMap class and if i exit the program,
    what will happen? the information that i put in the treeMap will be disappear??
    if it is like that,,how am i able to retrieve my data...when i restart my program..
    once i put ID as key and put my customer information,
    in it, after exit my program,, and i can't find
    my customers by their ID,,,,,,,,,how can,,i solve it......

    what will happen? the information that i put in the
    treeMap will be disappear??Yes. Of course. If you want data to hang around you have to tell the computer. If you want anything to happen you have to tell the computer.
    if it is like that,,how am i able to retrieve my
    data...when i restart my program..Tada! Tell the computer. Your simplest option is to use Serialization.
    Before exiting your program, serialize your TreeMap to disk. After starting your program serialize your TreeMap from disk.
    First stop should be your text book to learn what Serialization is and how it works, then try to write some code, then ask us to help with any problems.
    Dave.

  • I can get text messages and get this at the top of page 'Messages (-1)' can anyone help please?

    I can not get or see any text messages and get this at the top of page 'Messages (-1)' can anyone help please?

    For details of how to restore it, see https://support.mozilla.com/kb/menu+bar+is+missing

Maybe you are looking for

  • How can I set up the 'best' BI 3.1 + DS 3.2 environment?

    Hi, Recently, we have had several issues when we installed BI 3.1 on mahcines that already had Data Services (DS) 3.0. The problem is that when we install BI 3.1 on a macihe that already has DS 3.0, it breaks some of the xml files and some of the .ja

  • ToolTip for a report

    I have a big report. and now i want to show one column as a tool tip like the one in java. this means: for every row exists a specific column, named description, which should be shown as a tool tip. Is there a possibility to realize this?

  • @prompt used as part of Access Restriction

    We are struggling with implementing this, and wanted to check to see if this we can accomplish this.  We need to use an @prompt as part of an access restriction applied to the everyone group in order to force all users to select Group A, B or C at ru

  • What is this new 'Archive' folder?

    Hello, Can anyone explain what the new 'Archive' folder is and how it works? Many thanks, JC

  • Use of C/C++ Codes in LabVIEW

    How to use C/C++ compiled program in LAbVIEW?