zoukankan      html  css  js  c++  java
  • StringUtils方法

    org.apache.commons.lang.StringUtils中方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出NullPointerException,而是做了相应处理,例如,如果输入为null则返回也是null等,具体可以查看源代码)。

    除了构造器,StringUtils中一共有130多个方法,并且都是static的,

    所以我们可以这样调用StringUtils.xxx()。

    下面分别对一些常用方法做简要介绍:

    1. public static boolean isEmpty(String str)

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

    下面是示例:

    StringUtils.isEmpty(null)          = true

    StringUtils.isEmpty("")       = true

    StringUtils.isEmpty(" ")      = false

    StringUtils.isEmpty("        ")     = false

    StringUtils.isEmpty("bob")       = false

    StringUtils.isEmpty(" bob ") = false

    2. public static boolean isNotEmpty(String str)

    判断某字符串是否非空,等于!isEmpty(String str)

    下面是示例:

    StringUtils.isNotEmpty(null)        = false

    StringUtils.isNotEmpty("")           = false

    StringUtils.isNotEmpty(" ")      = true

    StringUtils.isNotEmpty("         ")    = true

    StringUtils.isNotEmpty("bob")   = true

    StringUtils.isNotEmpty(" bob ")   = true

  • 相关阅读:
    .Net 并发写入文件的多种方式
    变量命名神器——CODELF
    Python打包发布
    python工具——NumPy
    python工具——Pandas
    没事早点睡
    python工具——pixellib
    Tensorflow在Windows下使用踩坑
    python工具——Tesseract
    python工具——wordcloud
  • 原文地址:https://www.cnblogs.com/suiyisuixing/p/7443827.html
Copyright © 2011-2022 走看看