1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package
com.walker;
import
java.util.regex.Matcher;
import
java.util.regex.Pattern;
public
class
Tester {
public
static
void
main(String[] args) {
String str =
"123"
;
//true
System.out.println(isNumeric(str));
str =
"-123"
;
//true
System.out.println(isNumeric(str));
str =
"abc"
;
//false
System.out.println(isNumeric(str));
}
//@ author: walker
//用正则表达式判断字符串是否为数字(含负数)
public
static
boolean
isNumeric(String str) {
String regEx =
"^-?[0-9]+$"
;
Pattern pat = Pattern.compile(regEx);
Matcher mat = pat.matcher(str);
if
(mat.find()) {
return
true
;
}
else
{
return
false
;
}
}
}
|
*** walker ***
本文转自walker snapshot博客51CTO博客,原文链接http://blog.51cto.com/walkerqt/1361823如需转载请自行联系原作者
RQSLT