1、java判断字符串是否为整数或者小数:
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*\\.?[0-9]+");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
}
2、 java判断字符串是否为整数
public static boolean isInteger(String str) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
return pattern.matcher(str).matches();
}
参考:
java判断字符串是否为数字或小数_Li--AiTao的博客-CSDN博客_java判断是否是数字含有小数点
java判断字符串是否为整数_Java判断字符串是否为整数的方法有哪些_人工智能型AI少女的博客-CSDN博客
java判断字符串是否为数字的几种方式_Morning sunshine的博客-CSDN博客