ignoring the case

How does one integrate ignoring the case of an inputted character into a switch statement or while statement?

I know this

while("Y".equalsIgnoreCase(answer))

but I'd like to know how to do this for characters in a switch statement and while statement.

Thanks

[348 byte] By [datawerda] at [2007-11-26 20:02:25]
# 1
You could create a new string from the char or compare the input to both lower and uppercase versions
floundera at 2007-7-9 23:01:35 > top of Java-index,Java Essentials,New To Java...
# 2

I would do it in a while statement.

char a = 'a', b = 'b';

while( a.toLowerCase().equals(b.toLowerCase()) )

//and

while ( a.toUpperCase().equals(b.toUpperCase() )

For a switch (I would rather us a while loop)

char a = 'a', b = 'b';

char a1 = a.toLowerCase(), a2 = a.toUpperCase(), b1 = b.toLowerCase(), b2 = b2.toUpperCase

switch(a) {

case a1: //code

break;

case a2: //code

break;

case b1: //code

break;

case b2:: //code

break;

}

lethalwirea at 2007-7-9 23:01:35 > top of Java-index,Java Essentials,New To Java...
# 3
char a = 'a', b = 'b';while( a.toLowerCase().equals(b.toLowerCase()) )Can you show me where in the API these toLowerCase and equals methods are?
floundera at 2007-7-9 23:01:35 > top of Java-index,Java Essentials,New To Java...
# 4
The logic makes a lot of sense, but I thought you couldn't use the 'equals' operator on char types?!? Maybe it would be simpler to use String instead of char, but I want to use as little memory as is needed.
datawerda at 2007-7-9 23:01:35 > top of Java-index,Java Essentials,New To Java...
# 5
Character class:Lower Case: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Character.html#toLowerCase(char)Upper Case: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Character.html#toUpperCase(char)
lethalwirea at 2007-7-9 23:01:35 > top of Java-index,Java Essentials,New To Java...
# 6

Sorry sorry. My syntax is incorrect.

Should be

Character b1= Character.toUpperCase(b);

or

Character b2 = Character.toLowerCase(b);

*Edit

Also noting that you can write

char b = 'b';

char b1 = Character.toUpperCase(b);

char b2 = Character.toLowerCase(b);

Message was edited by:

lethalwire

Message was edited by:

lethalwire

Message was edited by:

lethalwire

lethalwirea at 2007-7-9 23:01:35 > top of Java-index,Java Essentials,New To Java...