Solved

Java - problem with IF Statement

Posted on 2012-04-05
5
294 Views
Last Modified: 2012-06-21
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
Comment
Question by:CipherIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 37814905
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
 
LVL 1

Author Comment

by:CipherIS
ID: 37814935
Nope didn't fix it.  Does not go in the If Statement.  I've attached a snapshot.
output.jpg
0
 
LVL 29

Expert Comment

by:QPR
ID: 37814940
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
 
LVL 1

Author Comment

by:CipherIS
ID: 37814944
i resolved it.

Ans is output.length == 0
0
 
LVL 14

Accepted Solution

by:
CPColin earned 500 total points
ID: 37814953
In the future, be sure to use String.equals() to compare a string. Using == to compare strings will not work.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question