java判断字符串是否为数字

String str ="222";
Pattern pattern = Pattern.compile("[0-9]*");
if(pattern.matcher(str).matches()){
System.out.println("是数字");
}else{
System.out.println("非数字");
}
posted @ 2021-12-24 11:10  northli  阅读(270)  评论(0编辑  收藏  举报