如何判断一个字符串是否为数字?
/**
* 判断是否为数字
* @param str String对象
* @return boolean :true 是;false : 不是。
* @author code_chen
* */
public static boolean isNumeric(String str){
try {
new BigDecimal(str);
return true ;
} catch (Exception e) {
return false ;
}
判断字符串是否为整数?????
/**0-9的正则表达式**/
public static final Pattern PATTERN = Pattern.compile("^[-\\+]?[\\d]*$");
/**
* 判断字符串是否为整数
* @param str String对象
* @return boolean :true 是;false : 不是。
* @author chenpeng
* */
public static boolean isInteger(String str){
return PATTERN.matcher(str).matches();
}