This article summarizes the Java implementation method to find numeric strings from strings. Share it for your reference, as follows:
int start = 0;String numStr = null;for (int j = 0; j < valuesStr.length() - 1; j++) { if (Character.isDigit(valuesStr.charAt(j)) == false && Character.isDigit(valuesStr.charAt(j + 1)) == true) { start = j + 1; numStr = valuesStr.substring(start, valuesStr.length()); }}There are three ways to reprint from other places:
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;}2. Use regular expressions
public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); return pattern.matcher(str).matches();}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.