Java - problem with IF Statement

I am having issues with the below piece of code.  I am using eclipse.  output is equal to "" but it does evaluate to true thereby not setting the value accordingly.  Any idea?

if(output == "")
{
    output = "Invalid characters entered."; 
}

Open in new window

LVL 1
CipherISAsked:
Who is Participating?
 
CPColinConnect With a Mentor Senior Java ArchitectCommented:
In the future, be sure to use String.equals() to compare a string. Using == to compare strings will not work.
0
 
QPRCommented:
trim your variable in case it isn't exactly an empy string e.g " "
If it's still not working then debug your code and step through to make sure you are actually reaching this step
0
 
CipherISAuthor Commented:
Nope didn't fix it.  Does not go in the If Statement.  I've attached a snapshot.
output.jpg
0
 
QPRCommented:
Well if it never reaches the if statement then there is something up with the logic. Can you step through the code and see why it doesn't get there?
0
 
CipherISAuthor Commented:
i resolved it.

Ans is output.length == 0
0
All Courses

From novice to tech pro — start learning today.