Android Check if String is Number: TextUtils.isDigitsOnly()

In Android, you can use the TextUtils.isDigitsOnly() method to determine if a string is a number. This method checks each character in the string to see if it is a digit, and will return true if all characters are digits, otherwise it will return false.

Here is the example code:

String str = "12345";
if(TextUtils.isDigitsOnly(str)) {
    Log.d("TAG", "字符串是数字");
} else {
    Log.d("TAG", "字符串不是数字");
}

This makes it very convenient to determine whether a string is a number.

bannerAds