comparison - Comparing chars in Java -
it's been while since i've done java syntax not greatest @ moment.
i want check char variable 1 of 21 specific chars, shortest way can this?
for example:
if(symbol == ('a'|'b'|'c')){}
doesn't seem working. need write like:
if(symbol == 'a' || symbol == 'b' etc.)
if input character , characters checking against consecutive try this:
if ((symbol >= 'a' && symbol <= 'z') || symbol == '?') { // ... }
however if input string more compact approach (but slower) use regular expression character class:
if (symbol.matches("[a-z?]")) { // ... }
if have character you'll first need convert string before can use regular expression:
if (character.tostring(symbol).matches("[a-z?]")) { // ... }
Comments
Post a Comment