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

    org.apache.commons.lang3 提供了String常用的操作,常用的有isEmpty(String str);isBlank(String str); 判断字符串是否为空、null、""等。
    <!--apache commons-->
    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.5</version>
    </dependency>

    StringUtils提供了许多的方法,可以通过StringUtils.xxx 看到,如下。

    1.StringUtils.isEmpty(str) 判断字符串内容是否为空,为空标准是str==null || str.length()==0,包括null、""。
    System.out.println(StringUtils.isEmpty(null));   结果 true
    System.out.println(StringUtils.isEmpty("")); 结果true
    System.out.println(StringUtils.isEmpty(" ")); 结果false
    System.out.println(StringUtils.isEmpty("aaa")); 结果false
    StringUtils.isNotEmpty(str) 等价于!str.isEmpty(str) 表示非空。

    2.StringUtils.isBlank(str)判断字符串内容为空,内容为空包括 null、""、" "。
    System.out.println(StringUtils.isBlank(null));  结果是true
    System.out.println(StringUtils.isBlank("")); 结果是true
    System.out.println(StringUtils.isBlank(" ")); 结果是true
    System.out.println(StringUtils.isBlank("aaa")); 结果是false
    
    
  • 相关阅读:
    0814防盗链访问控制代理
    0811Nginx访问日志设置
    0810Nginx安装
    0809LNMP架构介绍
    PHP安装
    mariaDB安装Apache安装(httpd)
    LAMP构架介绍
    shell基础知识(2)
    shell基础知识(1)
    yum更换国内源、yum下载rpm包、源码包安装
  • 原文地址:https://www.cnblogs.com/ming-blogs/p/10654463.html
Copyright © 2011-2022 走看看