Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/shy415502155/article/details/88838464
1 determines whether the string can be converted to a positive integer, (+, -, or zero)
public static Boolean isNumber (String STR) {
String REG = "^ [1-9] [0-9] {0,} $ ";
return str.matches (REG);
}
2. determining whether the string can be converted to integer or floating point
public static boolean isNumber(String str){
String reg = "^[0-9]+(.[0-9]+)?$";
return str.matches(reg);
}
3. determining whether the character string can be converted for all integers
public static boolean isNumber(String str){
String reg = "^\-{0,1}[0-9]{1,}$";
return str.matches(reg);
}