DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Returning string from method help (http://www.daniweb.com/forums/thread156983.html)

Nbutz Nov 12th, 2008 10:39 pm
Returning string from method help
 
I have this method:
    
public String addBuddy(String buddyName, HashMap userList)
{     
        if(buddyList.contains(buddyName))
            statusMessage = "Buddy already in list";
        else if (!userList.containsKey(buddyName))
            statusMessage = "No such user on server";           
        else
            buddyList.add(buddyName);
            statusMessage = "Buddy added";
        return (statusMessage);
    }

When I call this in my main how would i display the statusMessage? statusMessage is declared so that's not the problem

In my main I'm calling:

           if (option == 3)
          {
              System.out.println("enter user name: ");
              String buddyName = a.nextLine();
              server.userList.get(user).addBuddy(buddyName, server.userList);
          }
Thanks for the help

dickersonka Nov 12th, 2008 10:50 pm
Re: Returning string from method help
 
System.out.println(addBuddy(buddyName, server.userList));


All times are GMT -4. The time now is 10:53 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC