Solved

Java - problem with IF Statement

Posted on 2012-04-05
5
293 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 101
hibernate example for saving data 19 106
Running JavaFX on JDeveloper 12C 1 105
Java syntax, or is it Selenium 6 57
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

738 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