wood burning stoves 2.0*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "equalsIgnoreCase" Watch "equalsIgnoreCase" New topic
Author

equalsIgnoreCase

Debbie Chaney
Greenhorn

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.

Example:
marc weber
Sheriff

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
sscce.org
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'.
 
wood burning stoves
 
subject: equalsIgnoreCase
 
Similar Threads
need help with exception
method help
StringTokenzier
Scanner class help
Random array string that doesn't repeat