首页 > 其他 > 详细

判断字符串是不是数字的方法

时间:2016-09-09 16:40:26      阅读:82      评论:0      收藏:0      [点我收藏+]

判断字符串是不是数字?

方法一:

/**
* 用于验证获取的字符串是不是数字
* @param str
* @return
*/
public static boolean isNumeric(String str) {
  for (int i = 0; i < str.length(); i++) {
  // 验证字符串中的字符是不是数字
    if (!Character.isDigit(str.charAt(i))) {
      return false;
    }
  }
  return true;
}

 

方法二:

// 判断月份是否为空或者是否为非数字,正则表达式
public static boolean isVaild(String s) {
  Pattern pattern = Pattern.compile("[0-9]*");
  Matcher isNum = pattern.matcher(s);

  if (s != null && isNum.matches()) {
    return true;
  }
  return false;
}

 

拿走,不谢~O(∩_∩)O~

判断字符串是不是数字的方法

原文:http://www.cnblogs.com/yoghurt/p/5857034.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!