public static void main(String[] args) {
System.out.println(isNumber("-12.3"));
}
private static boolean isNumber(String str){
// Pattern pattern = Pattern.compile("\\d+"); 纯数字
Pattern pattern = Pattern.compile("-?[0-9]+(\\.[0-9]+)?"); // 包含小数与负数
Matcher matcher = pattern.matcher(str);
return matcher.matches();
}