String str ="222";Pattern pattern = Pattern.compile("[0-9]*");if(pattern.matcher(str).matches()){ System.out.println("是数字");}else{ System.out.println("非数字");}