Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java - problem with IF Statement

Posted on 2012-04-05
5
Medium Priority
?
296 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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