java中判断字符串是否为数字的三种方法

以下内容引自  http://www.blogjava.net/Javaphua/archive/2007/06/05/122131.html
1用JAVA自带的函数
 
1 public static boolean isNumeric(String str){
2   for (int i = str.length();--i>=0;){   
3    if (!Character.isDigit(str.charAt(i))){
4     return false;
5    }
6   }
7   return true;
8  }
View Code

2用正则表达式
1 public static boolean isNumeric(String str){ 
2     Pattern pattern = Pattern.compile("[0-9]*"); 
3     return pattern.matcher(str).matches();    
4  } 

3用ascii码

1 public static boolean isNumeric(String str){
2    for(int i=str.length();--i>=0;){
3       int chr=str.charAt(i);
4       if(chr<48 || chr>57)
5          return false;
6    }
7    return true;
8 }