不迷迷糊糊,直接整代码
判断字符串是否是数字:
/**
* 判断是否为数字,是:返回true
* @param str
* @return
*/
public static boolean isNumeric(final String str) {
// null or empty
if (str == null || str.length() == 0) {
return false;
}
try {
Integer.parseInt(str);
return true;
} catch (NumberFormatException e) {
try {
Double.parseDouble(str);
return true;
} catch (NumberFormatException ex) {
try {
Float.parseFloat(str);
return true;
} catch (NumberFormatException exx) {
return false;
}
}
}
}