JAVA判断字符串是否为数字
2010-07-15 13:48
295 查看
1.Java
自带的函数
public static boolean isNumeric(String str) {
for (int i = str.length(); --i >= 0;) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
2.正则表达式
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
3.还是正则表达式public static boolean isNumeric(String str) {
if (str.matches("//d
*")) {
return true;
}
return false;
}
4.用ascii码
public static boolean isNumeric(String str) {
for (int i = str.length(); --i >= 0;) {
int chr = str.charAt(i);
if (chr < 48 || chr > 57)
return false;
}
return true;
}
转载:http://java.chinaitlab.com/base/801693.html
自带的函数
public static boolean isNumeric(String str) {
for (int i = str.length(); --i >= 0;) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
2.正则表达式
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
3.还是正则表达式public static boolean isNumeric(String str) {
if (str.matches("//d
*")) {
return true;
}
return false;
}
4.用ascii码
public static boolean isNumeric(String str) {
for (int i = str.length(); --i >= 0;) {
int chr = str.charAt(i);
if (chr < 48 || chr > 57)
return false;
}
return true;
}
转载:http://java.chinaitlab.com/base/801693.html
相关文章推荐
- JAVA判断字符串是否为数字
- java判断字符串是否为数字
- Java中判断字符串是否为数字的五种方法
- JAVA判断字符串是否为数字
- java判断字符串是否为数字
- java中判断字符串是否为数字的方法
- java判断字符串是否为数字或中文或字母
- java中判断字符串是否为数字的方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的方法 StringUtil包函数
- JAVA判断字符串是否为数字
- java中判断字符串是否为数字的方法的几种方法
- java中判断字符串是否为数字的方法的几种方法
- java中判断字符串是否为数字的方法的几种方法
- java中判断一个字符串是否“都为数字”和“是否包含数字”和“截取数字”
- java中判断字符串是否数字的两种方法
- java中判断字符串是否为数字的方法的几种方法
- [转]java中判断字符串是否为数字的三种方法
- Java中判断字符串是否为数字的五种方法
- Java判断字符串是否全由数字组成