zoukankan      html  css  js  c++  java
  • StringUtils工具类详解

    StringUtils判断字符串大概有四种方法:

    下面是 StringUtils 判断是否为空的示例: 

    判断是否为空,但是要注意,空格不算空,这个最好能不用则不用。

    StringUtils.isEmpty(null) = true

      StringUtils.isEmpty("") = true

      StringUtils.isEmpty(" ") = false //注意在 StringUtils 中空格作非空处理 

      StringUtils.isEmpty("   ") = false

      StringUtils.isEmpty("bob") = false

      StringUtils.isEmpty(" bob ") = false

    判断某字符串是否非空,这个和上面的判断正好相反,不推荐使用:

    StringUtils.isNotEmpty(null) = false

      StringUtils.isNotEmpty("") = false

      StringUtils.isNotEmpty(" ") = true

      StringUtils.isNotEmpty("         ") = true

      StringUtils.isNotEmpty("bob") = true

      StringUtils.isNotEmpty(" bob ") = true

    判断某字符串是否为空或长度为0,这个推荐使用:

    StringUtils.isBlank(null) = true

      StringUtils.isBlank("") = true

      StringUtils.isBlank(" ") = true

      StringUtils.isBlank("        ") = true

      StringUtils.isBlank(" f ") = true   //对于制表符、换行符、换页符和回车符 

      StringUtils.isBlank()   //均识为空白符 

      StringUtils.isBlank("") = false   //""为单词边界符 

      StringUtils.isBlank("bob") = false

      StringUtils.isBlank(" bob ") = false

    判断某字符串是否不为空且长度不为0,这个和上面的正好相反,推荐使用:

    StringUtils.isNotBlank(null) = false

      StringUtils.isNotBlank("") = false

      StringUtils.isNotBlank(" ") = false

      StringUtils.isNotBlank("         ") = false

      StringUtils.isNotBlank(" f ") = false

      StringUtils.isNotBlank("") = true

      StringUtils.isNotBlank("bob") = true

      StringUtils.isNotBlank(" bob ") = true

  • 相关阅读:
    [数据结构与算法]Note
    [C++]构造函数那些事
    [C++]constexpr函数
    [计算机系统]字/字节/位
    [C++]返回数组指针
    [C++]Top-level const/Low-level const
    [信号]预加重与去加重--转
    Smart solution of decode String
    ACE学习:
    模糊匹配算法
  • 原文地址:https://www.cnblogs.com/suiyisuixing/p/7892184.html
Copyright © 2011-2022 走看看