环境:Jdk11

1. 是否为数字

    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^-?\\d+$");
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }

2. 是否为小数

    public static boolean isDecimal(String str) {
        Pattern pattern = Pattern.compile("^-?\\d+\\.\\d+$");
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }