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

Daniel Sopel picture Daniel Sopel · Oct 29, 2010 · Viewed 320.9k times · Source

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

Answer

Adam picture Adam · Oct 29, 2010

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