Solved

Strange if, if else execution

Posted on 2007-11-29
1
130 Views
Last Modified: 2010-05-18
Hi,

I'm not sure why this if/else statement is skipping over my first case. I have a string with the contents:

     "nearestneighbor"

then the code that checks it:

                if (strCode == "nearestneighbor")
                {
                    System.out.println("using nn");
                    m_ImageQuality = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
                }
                else if (strCode == "bilinear")
                {
                    System.out.println("using bilinear");
                    m_ImageQuality = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
                }
                else if (strCode == "bicubic")
                {
                    System.out.println("using bicubic");
                    m_ImageQuality = RenderingHints.VALUE_INTERPOLATION_BICUBIC;
                }
                System.out.println("The value of strCode was [" + strCode + "].");

Now it doesn't enter the first if block, which I think it should. The print out at the end of the cases verifies the contents, here's what's printed out:


    The value of strCode was [nearestneighbor].

I must be missing something really silly, why is it not matching?

Thanks

0
Comment
Question by:DJ_AM_Juicebox
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 20379552
== tests for object equality
use equals() method to test string equality

eg.                 if (strCode.equals("nearestneighbor"))
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
This video teaches viewers about errors in exception handling.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now