Daniel Sopel Daniel Sopel - 22 days ago 6
Java Question

What is the best way to tell if a character is a letter or number in Java without using regexes?

What is the best and/or easiest to learn way to recognize if a string.charAt(index) is an A-z letter or a number in Java without using regular expressions? Thanks.

Answer

Character.isDigit(string.charAt(index)) (javadoc) will return true if it's a digit
Character.isLetter(string.charAt(index)) (javadoc) will return true if it's a letter