• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

What's wrong with this If statement  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code looks fine. Are you sure it's a capital letter "i", and not a vertical bar (|) or lower case letter "L" (l) ?
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is cclass a String?
 
jay donald
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!