Equals statement being valid for both uppercase and lowercase of the same letter

Leo Messi :

Having var toCheck = a

In this case if(toCheck == 'a') returns true

Is there a shorter/better way that this operation returns true for A also?\

Something different of if(toCheck == 'a' || toCheck == 'A')

user2864740 :

Since starting with a character, Character.toLowerCase might be suitable.

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

if (Character.toLowerCase(toCheck) == 'a') return true;

Or, conversely as Elliott points out:

if (Character.toUpperCase(toCheck) == 'A') return true;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=112233&siteId=1
Recommended