Search code examples
javacharnumbersletter

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 way to recognize if a string.charAt(index) is an A-z letter or a number in Java without using regular expressions? Thanks.


Solution

  • 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