java 判断字符串是否为数字(包含负数)

public static void main(String[] args){
System.out.println(AssistController.isNumeric("-77"));
}

public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("-?[0-9]+(\\\\.[0-9]+)?");
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() ){
return false;
}
return true;
}

猜你喜欢

转载自www.cnblogs.com/cjb1/p/9988537.html