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

Popular posts from this blog

jQuery clickable div with working mailto link inside -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -