1. Java-brought functions public static Boolean isnumeric (String str) {for (int i = 0; i < str.length (); i++) {System.out.print
ln (Str.charat (i)); if (!
Character.isdigit (Str.charat (i)) {return false;
} return true; 2. First import Java.util.regex.Pattern and Java.util.regex.Matcher public boolean isnumeric with regular expressions (String str) {pattern
Pattern = Pattern.compile ("[0-9]*");
Matcher isnum = Pattern.matcher (str);
if (!isnum.matches ()) {return false;
return true;
3. Use of Org.apache.commons.lang org.apache.commons.lang.StringUtils;
Boolean isnunicodedigits=stringutils.isnumeric ("aaa123456789"); Http://jakarta.apache.org/commons/lang/api-release/index.html The following explanation: IsNumeric public static Boolean IsNumeric ( String str) Checks If the string contains only Unicode digits.
A decimal point are not a Unicode digit and returns false. Null would return FALSE.
An empty String ("") would return true. Stringutils.isnumeric (NULL) = False Stringutils.isnumeric ("") = TruE stringutils.isnumeric ("") = False Stringutils.isnumeric ("123") = True Stringutils.isnumeric ("3") = False Str Ingutils.isnumeric ("ab2c") = False Stringutils.isnumeric ("12-3") = False Stringutils.isnumeric ("12.3") = False Paramet
Ers:str-the String to check, the second method is more flexible in the three of the above methods, may being null returns:true if only contains digits. The first to third way can only verify a number with no minus sign "-", that is, enter a negative 199, the output will be false, and the second way you can modify the regular expression to implement a checksum negative, modify the regular expression to "^-?" [0-9]+] can be modified to "-?" [0-9]+.? [0-9]+] matches all numbers.