This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What's wrong with this If statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Watch "What New topic
Author

What's wrong with this If statement

jay donald
Greenhorn

Joined: Feb 09, 2006
Posts: 20
Hi,
I'm going crazy with this statement. I am getting a String returned from a method and then checking if it isn't certain value. If it's not, then print something. Here's the code:

To my understanding, the above if statement checks to see if cclass is not equal to II or IC and then, prints the statement. But, it's printing the statement even if cclass is IC. I'm really confused. Could someone please tell me what i'm doing wrong. Thanks.
[ March 15, 2006: Message edited by: jay donald ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Code looks fine. Are you sure it's a capital letter "i", and not a vertical bar (|) or lower case letter "L" (l) ?


[Jess in Action][AskingGoodQuestions]
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
I agree, the code looks fine.

Try printing out the value of each individual expression - cclass.equalsIgnoreCase("II") , cclass.equalsIgnoreCase("IC") and the expression (cclass.equalsIgnoreCase("II") || cclass.equalsIgnoreCase("IC")) .
jay donald
Greenhorn

Joined: Feb 09, 2006
Posts: 20
Hi,
Thanks for your response. Yeah It's IC. Ok, this is what i did:

and guess what ..it's printing false when it should be printing true. Man, i'm going nuts over here.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Is cclass a String?
jay donald
Greenhorn

Joined: Feb 09, 2006
Posts: 20
Hey Ernest,
yes, it's a String (that's why im using equals()). THis class is part of a web application and i'm using test enviornment of WSAD 5.1.
[ March 15, 2006: Message edited by: jay donald ]
jay donald
Greenhorn

Joined: Feb 09, 2006
Posts: 20
I finally figured it out. The String i was getting back from the method is a column in a table with a char datatype. So, it was adding a "blank" to the string since the length of that column is defined as 3. So, trim() did the trick. Thanks for your help.
 
wood burning stoves
 
subject: What's wrong with this If statement
 
Similar Threads
which has more priority: || and &&
component layout not wrapping inside Panel
operator
Class casting/assigning question - REVISED
IF statement