Code example:
/** * 判断字符串是否为数字 */ public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(str); return isNum.matches(); }
(Free video tutorial recommendation:java video tutorial)
Test:
public static void main(String[] args) { String str = "11"; String str1 = "11sdf"; System.out.println(isNumeric(str)); System.out.println(isNumeric(str1)); }
Output results:
true false
Recommended related articles and tutorials:java introductory tutorial
The above is the detailed content of Java determines whether a string is an integer number. For more information, please follow other related articles on the PHP Chinese website!