Problem using isDigit ()

I am trying to use isDigit () to check if a character in a string is a digit.

if (aString.charAt(i).isDigit == false) 

I get an error: I cannot call isDigit on a character of primitive type. What am I doing wrong?

+4
source share
1 answer

This is a static method in the Character class, so you need to:

 if (!Character.isDigit(aString.charAt(i))) 

(Note the use of ! Instead of comparing the result with false , btw. Both methods will work, but I see the above as more idiomatic.)

+19
source

All Articles