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

    故乡明
  • 相关阅读:
    [FlareOn4]greek_to_me
    [FlareOn1]Sploitastic
    [FlareOn1]Creation
    [FlareOn1]5get_it
    esxi6.7中,显卡设置为直通步骤
    esxi6.7安装步骤
    nmcli命令详解
    查看指定进程的IO/CPU/MEM/带宽/显卡
    使用WSGIServer修改静态文件
    k8s配置多端口ingress
  • 原文地址:https://www.cnblogs.com/luweiweicode/p/15132047.html
Copyright © 2011-2022 走看看