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

    实际应用中,经常会用到判断字符串是否为空的逻辑

    比较简单的就是用 Str != null && Str.length() >0   来判断

    其实很多java工具集都是有包装好的接口可以使用的

    比如   StringUtils.isEmpty(String str) 和 StringUtils.isBlank(String str)

    isEmpty和isBlank的区别在于

    isEmpty仅仅是判断空和长度为0字符串

    isBlank判断的是空,长度为0,空白字符(包括空格,制表符 ,换行符 ,换页符f,回车 )组成的字符串。

    比如:

    StringUtils.isEmpty(null) = true

    StringUtils.isEmpty("") = true

    StringUtils.isEmpty(" ") = false

    StringUtils.isEmpty("aaa") = false

    StringUtils.isEmpty(" f") = false

    StringUtils.isBlank(null) = true

    StringUtils.isBlank("") = true

    StringUitls.isBlank(" ") = true

    StringUtils.isEmpty("aaa") = false

    StringUtils.isEmpty(" f") = true

    顺便在引包的时候,会出现org.apache.commons.lang和org.apache.commons.lang3两种选择,lang3是Apache Commons 团队发布的工具包,要求jdk版本在1.5以上,相对于lang来说完全支持java5的特性,废除了一些旧的API。

    所以引用lang3就好啦

  • 相关阅读:
    nginx源码分析——http模块
    linux 信号处理
    文件读写监控(inotify, systemtap)
    rem
    vscode 将本地项目上传到码云
    vue 模拟去哪网
    form 文件上传
    分页
    修改默认select样式
    模拟select下拉框、复选框效果
  • 原文地址:https://www.cnblogs.com/westlife-11358/p/11326458.html
Copyright © 2011-2022 走看看