java判断是否为数字

时间:2020-05-20 14:33:29   收藏:0   阅读:48
//采用正则表达式的方式来判断一个字符串是否为数字,这种方式判断面比较全  
        //可以判断正负、整数小数  
        //?:0或1个, *:0或多个, +:1或多个  
        Boolean strResult = str.matches("-?[0-9]+.*[0-9]*");  
          
if(strResult == true) {  
            System.out.println("Is Number!");  
        } else {  
            System.out.println("Is not Number!"); 

  

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!