Porixify Porixify - 1 month ago 6
Java Question

How would I go about comparing two character that will convert to the same character?

So basically, I want to use the switch statement. I have a chart for each encoded character that a user will enter. However, each uppercase character and lowercase character has the same meaning. I find it unnecessary to copy each switch statement and revise the same thing. So how would I come about this?

Answer

You can use the function toUpperCase:

Converts the character argument to uppercase using case mapping information from the UnicodeData file.

switch (Character.toUpperCase(character)) {
    case 'A':
        // code ...
        break;
    case 'B':
        // code ...
        break;
    ...
    default:
        // default code
}
Comments