第一种利用java自带的函数
public static boolean isNumeric(String str){ for(i<str.length();--i>=0;){ if(!Character.isDigit(str.CharAt(i))){ return false; } } return true; }
第二种利用正则表达式
public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); }