zoukankan      html  css  js  c++  java
  • StringUtils类中isEmpty与isBlank的区别

    原文地址:https://www.cnblogs.com/dennisit/p/3705374.html

    org.apache.commons.lang.StringUtils类提供了String的常用操作,最为常用的判空有如下两种isEmpty(String str)和isBlank(String str)。

    StringUtils.isEmpty(String str) 判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0

    System.out.println(StringUtils.isEmpty(null));        //true
    System.out.println(StringUtils.isEmpty(""));          //true
    System.out.println(StringUtils.isEmpty("   "));       //false
    System.out.println(StringUtils.isEmpty("dd"));        //false

    StringUtils.isNotEmpty(String str) 等价于 !isEmpty(String str)

    StringUtils.isBlank(String str) 判断某字符串是否为空或长度为0或由空白符(whitespace) 构成

    System.out.println(StringUtils.isBlank(null));        //true
    System.out.println(StringUtils.isBlank(""));          //true
    System.out.println(StringUtils.isBlank("   "));       //true
    System.out.println(StringUtils.isBlank("dd"));        //false    

    StringUtils.isBlank(String str) 等价于 !isBlank(String str)

  • 相关阅读:
    WPF 便签项目
    .NET下WPF学习之Socket通信
    DEV控件
    字符串位数补足
    VS2008设置断点不命中
    错误描述: 242000021
    关闭Win10自带的 Windows Defender
    启用与关闭 Ad Hoc Distributed Queries
    Date工具类
    数据字段脱敏
  • 原文地址:https://www.cnblogs.com/eyesfree/p/9277387.html
Copyright © 2011-2022 走看看