关于 String 的判空:
判断字符串是否为数字:
// 使用正则表达式
public static boolean isNumeric(String number) {
Pattern pattern = Pattern.compile(\"[0-9]*\");
return pattern.matcher(str).matches();
}
// 利用ASCII码
public static boolean isNumeric(String number) {
for (int i = str.length(); --i >= 0;) {
int chr = str.charAt(i);
if (chr < 48 || chr > 57)
return false;
}
return true;
}
本文地址:https://www.stayed.cn/item/10485
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我