• 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

equalsIgnoreCase

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to make this so that whatever the user enters, a "Y" or a "y" or a "N" or a "n", it will have no effect on the outcome. In my book, equalsIgnoreCase is supposed to be used with a boolean, but I have "again" as a character. I'm not sure how to write it.

System.out.println ("Do you want to enter a new job? "
+ "(\"Y\" to do this again, \"N\" to see all results.)");
again = write.nextChar();

}

while (again != N);
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The equalsIgnoreCase() method is used to compare String objects. You can either convert the char to a String (in which case, you'll be able to use that method), or you can simply compare char values with the == operator.

Example:
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Debbie Chaney:
...equalsIgnoreCase is supposed to be used with a boolean...


equalsIgnoreCase is a method in the String class that takes an Object (presumably a String) as an argument and returns a boolean. But in your situation, you appear to be using primitive chars rather than Strings.

If you're using chars, you could simply test for either case of 'Y'...

if( (myChar == 'Y') || (myChar == 'y') ) {...}

Note that char literals are enclosed in single quotes.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or you could just aoply the toLowerCase method on input and compare the input with 'y' and 'n'.
reply
    Bookmark Topic Watch Topic
  • New Topic