File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes equalsIgnoreCase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "equalsIgnoreCase" Watch "equalsIgnoreCase" New topic


Debbie Chaney

Joined: Jul 25, 2005
Posts: 1
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);
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

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.

marc weber

Joined: Aug 31, 2004
Posts: 11343

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.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
jin sun
Ranch Hand

Joined: Feb 16, 2005
Posts: 30
or you could just aoply the toLowerCase method on input and compare the input with 'y' and 'n'.
I agree. Here's the link:
subject: equalsIgnoreCase
It's not a secret anymore!