1、字符串匹配为数字:
if(str.charAt(i)>=48 && str.charAt(i)<=57){
str2+=str.charAt(i);
}
2、用正则表达式
public static boolean isNumericzidai(String str) {
Pattern pattern = Pattern.compile("-?[0-9]+\\.?[0-9]*");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
}