用正则表达式
首先要import java.util.regex.Pattern 和 java.util.regex.Matcher
public boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() ){
return false;
}
return true;
}
用正则表达式判断一个字符串是否全是数字
最新推荐文章于 2024-04-15 10:13:25 发布
本文介绍了一种使用Java正则表达式验证字符串是否全为数字的方法。通过import语句引入必要的包,并提供了一个名为isNumeric的公共方法,该方法接受一个字符串参数并返回布尔值以指示输入字符串是否仅由数字组成。
3万+

被折叠的 条评论
为什么被折叠?



