zoukankan      html  css  js  c++  java
  • 判断字符串是不是数字的方法

    判断字符串是不是数字?

    方法一:

    /**
    * 用于验证获取的字符串是不是数字
    * @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~

  • 相关阅读:
    第32周二
    第32周一
    第31周日
    第31周六
    第31周五
    第31周四
    第31周三
    C++中this指针的使用方法.
    ArcPad 10 的安装部署
    UEditor用法
  • 原文地址:https://www.cnblogs.com/yoghurt/p/5857034.html
Copyright © 2011-2022 走看看