摘自:https://blog.csdn.net/qq_42133100/article/details/92158507
2 public static boolean isNumeric(String str){ 3 for (int i = str.length();--i>=0;){ 4 if (!Character.isDigit(str.charAt(i))){ 5 return false; 6 } 7 } 8 return true; 9 }
public static boolean isInteger(String str) { Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); return pattern.matcher(str).matches(); }
public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); }
public final static boolean isNumeric(String s) { if (s != null && !"".equals(s.trim())) return s.matches("^[0-9]*$"); else return false; }
public static boolean isNumeric(String str){ for(int i=str.length();--i>=0;){ int chr=str.charAt(i); if(chr<48 || chr>57) return false; } return true; }
try { //Integer num = Integer.valueOf(str); Double num2 = Double.valueOf(str); //System.out.println("Is Number!" + num); System.out.println("Is Number!" + num2); } catch (Exception e) { System.out.println("Is not Number!"); }
//?:0或1个, *:0或多个, +:1或多个 Boolean strResult = str.matches("-?[0-9]+.?[0-9]*"); if(strResult == true) { System.out.println("Is Number!"); } else { System.out.println("Is not Number!"); }
原文:https://www.cnblogs.com/xinruyi/p/11518617.html