java 判断字符串是否为整数(亲测)

正则表达式

    /*
     * 判断是否为整数
     * @param str 传入的字符串
     * @return 是整数返回true,否则返回false
     */


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

备注:此文章转载于他人,仅做学习使用。

发布了51 篇原创文章 · 获赞 69 · 访问量 9828

猜你喜欢

转载自blog.csdn.net/weixin_43671437/article/details/105009364