Solved

Strange if, if else execution

Posted on 2007-11-29
1
137 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 500 total points
ID: 20379552
== tests for object equality
use equals() method to test string equality

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe 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
use lov values 2 72
String array comparison 4 46
Why doesn't this text field show up on my Applet frame? 2 28
activeMQ Queue Messages Enqueued and Messages Dequeued 1 39
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

726 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