Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Quick Java Problem

  • 26-03-2009 6:41pm
    #1
    Closed Accounts Posts: 20


    I am recieving input from the user, and then I want to check if they actually entered anything:

    String searchValue = JOptionPane.showInputDialog(this, "Enter the node value you are looking for");


    //Check that the user entered something
    if(searchValue != "")
    {

    But that if statement returns true even if I leave the text box empty. What am I doing wrong?

    Cheers


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    You are comparing Objects, not strings. Looks into the String equals method.


  • Closed Accounts Posts: 20 Whackhead


    You are comparing Objects, not strings. Looks into the String equals method.

    Cheers, had forgotten about that.


  • Registered Users, Registered Users 2 Posts: 378 ✭✭sicruise


    You can also use the apache commons StringUtils method isNotEmpty

    Will work better and will avoid NPE's


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    sicruise wrote: »
    You can also use the apache commons StringUtils method isNotEmpty

    Why pull in a whole library for 1 line of code?

    s != null && !s.equals("")


Advertisement