判断一组字符是否是数字

public static boolean isNumber(String str)
    {
        boolean isTrue = false;
        if (!str.contains(" "))
        {
            StringBuffer sb = new StringBuffer("");
            for (int i = 1; i <= str.length(); i++)
            {
                sb.append("[0-9]");
            }
            Pattern pat = Pattern.compile(sb.toString());
            Matcher matcher = pat.matcher(str);
            if (matcher.matches())
            {
                isTrue = true;
            }
        }
        return isTrue;
    }

你可能感兴趣的:(数字)