?
Solved

Strange if, if else execution

Posted on 2007-11-29
1
Medium Priority
?
149 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
[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
1 Comment
 
LVL 92

Accepted Solution

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

eg.                 if (strCode.equals("nearestneighbor"))
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

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 connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

764 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