Strange if, if else execution

Posted on 2007-11-29
Medium Priority
Last Modified: 2010-05-18

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


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?


Question by:DJ_AM_Juicebox
1 Comment
LVL 92

Accepted Solution

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

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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
The viewer will learn how to implement Singleton Design Pattern in Java.
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

600 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