• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What's wrong with this If statement

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is cclass a String?
 
jay donald
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic