This article summarizes the method of java to determine whether a string is a number. Share it for your reference, as follows:
Method 1: Use the functions that come with JAVA
public static boolean isNumeric(String str){ for (int i = str.length();--i>=0;){ if (!Character.isDigit(str.charAt(i))){ return false; } } return true;}Method 2: Use regular expressions
public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches(); }Method 3: Use ascii code
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;}I hope this article will be helpful to everyone's Java programming.