(一)利用正則表達式判斷某個字符串是否是數字
public static boolean isNumeric(String s) {// 正則表達式return (s.matches("\\d*") && Pattern.compile("[0-9]*").matcher(s).matches());}
?
(二)利用格式轉換異常來確定
// 判斷字符串是否為數字public boolean isInteger(String value) {try {Integer.parseInt(value);return true;} catch (NumberFormatException e) {return false;}}
?