方法一:用JAVA自带的函数
publicstaticbooleanisNumeric(Stringstr){for(inti=str.length();--i>=0;){if(!Character.isDigit(str.charAt(i))){returnfalse;}}returntrue;}
方法二:
/**判断是否为整数*@paramstr传入的字符串*@return是整数返回true,否则返回false*/publicstaticbooleanisInteger(Stringstr){Patternpattern=Pattern.compile("^[-\\+]?[\\d]*$");returnpattern.matcher(str).matches();}
方法三:
publicstaticbooleanisNumeric(Stringstr){Patternpattern=Pattern.compile("[0-9]*");returnpattern.matcher(str).matches();}
方法四:
publicfinalstaticbooleanisNumeric(Strings){if(s!=null&&!"".equals(s.trim()))returns.matches("^[0-9]*$");elsereturnfalse;}
方法五:用ascii码
publicstaticbooleanisNumeric(Stringstr){for(inti=str.length();--i>=0;){intchr=str.charAt(i);if(chr<48||chr>57)returnfalse;}returntrue;}