Solved

Strange if, if else execution

Posted on 2007-11-29
1
128 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 77
array6 challenfge 6 63
What is JNDI datasource in spring 1 38
Python Assistance 7 35
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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.
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 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

19 Experts available now in Live!

Get 1:1 Help Now