如何判断一个字符串是否为数字??如何判断字符串是否为整数???

如何判断一个字符串是否为数字?

 /**
     * 判断是否为数字
     * @param str String对象 
     * @return boolean :true 是;false : 不是。
     * @author code_chen
     * */
    public static boolean isNumeric(String str){
         try {
             new BigDecimal(str);
             return true ;
        } catch (Exception e) {
            return false ;
        }
    

判断字符串是否为整数?????

 

   /**0-9的正则表达式**/
    public static final Pattern PATTERN = Pattern.compile("^[-\\+]?[\\d]*$");  

    /**
     * 判断字符串是否为整数
     * @param str String对象
     * @return boolean :true 是;false : 不是。
     * @author chenpeng
     * */
    public static boolean isInteger(String str){  
            return PATTERN.matcher(str).matches();  
    }


版权声明:本文为qq_20446879原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。