關于 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;
}
新聞熱點
疑難解答