[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

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

0
CipherIS
Asked:
CipherIS
  • 2
  • 2
1 Solution
 
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
 
CPColinCommented:
In the future, be sure to use String.equals() to compare a string. Using == to compare strings will not work.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now