zoukankan      html  css  js  c++  java
  • isEmpty 和 isBlank 的用法区别

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>

    StringUtils.isEmpty()

    是否为空. 可以看到 " " 空格是会绕过这种空判断,因为是一个空格,并不是严格的空值,会导致 isEmpty(" ")=false

    StringUtils.isEmpty(null) = true
    StringUtils.isEmpty("") = true
    StringUtils.isEmpty(" ") = false
    StringUtils.isEmpty(“bob”) = false
    StringUtils.isEmpty(" bob ") = false
    public static boolean isEmpty(final CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

    StringUtils.isNotEmpty()

    相当于不为空 , = !isEmpty()

    public static boolean isNotEmpty(final CharSequence cs) {
            return !isEmpty(cs);
        }

    StringUtils.isAnyEmpty()

    是否有一个为空,只有一个为空,就为true.

    StringUtils.isAnyEmpty(null) = true
    StringUtils.isAnyEmpty(null, “foo”) = true
    StringUtils.isAnyEmpty("", “bar”) = true
    StringUtils.isAnyEmpty(“bob”, “”) = true
    StringUtils.isAnyEmpty(" bob ", null) = true
    StringUtils.isAnyEmpty(" ", “bar”) = false
    StringUtils.isAnyEmpty(“foo”, “bar”) = false
    /**
     * @param css  the CharSequences to check, may be null or empty
     * @return {@code true} if any of the CharSequences are empty or null
     * @since 3.2
     */
    public static boolean isAnyEmpty(final CharSequence... css) {
      if (ArrayUtils.isEmpty(css)) {
        return true;
      }
      for (final CharSequence cs : css){
        if (isEmpty(cs)) {
          return true;
        }
      }
      return false;
    }

    StringUtils.isNoneEmpty()

    相当于!isAnyEmpty(css) , 必须所有的值都不为空才返回true

    /**
     * <p>Checks if none of the CharSequences are empty ("") or null.</p>
     *
     * <pre>
     * StringUtils.isNoneEmpty(null)             = false
     * StringUtils.isNoneEmpty(null, "foo")      = false
     * StringUtils.isNoneEmpty("", "bar")        = false
     * StringUtils.isNoneEmpty("bob", "")        = false
     * StringUtils.isNoneEmpty("  bob  ", null)  = false
     * StringUtils.isNoneEmpty(" ", "bar")       = true
     * StringUtils.isNoneEmpty("foo", "bar")     = true
     * </pre>
     *
     * @param css  the CharSequences to check, may be null or empty
     * @return {@code true} if none of the CharSequences are empty or null
     * @since 3.2
     */
    public static boolean isNoneEmpty(final CharSequence... css) {

    https://mp.weixin.qq.com/s/hlSQbTRRzLNZvr_eu_lT_g

    故乡明
  • 相关阅读:
    php生成excel
    gearmand
    开启Nginx的目录文件列表功能
    zend框架学习
    引用方法形成树
    智能指针实现
    图文例解C++类的多重继承与虚拟继承
    CC++定位崩溃代码行的方法
    C++函数重定义、重载、重写
    勤奋吧,一天一点,努力提高基本技能。
  • 原文地址:https://www.cnblogs.com/luweiweicode/p/15132047.html
Copyright © 2011-2022 走看看