Apache Commons Lang的StringUtils.isEmpty(STR)和StringUtils.isBlank(STR)
Apache Commons Lang是常用的基础框架,其中字符串判空在项目中尤为常用,而自己常常忘记他们的区别。
package com.nicchagil.test;
import org.apache.commons.lang3.StringUtils;
public class Call {
public static void main(String[] args) {
String NULL_STR = null;
String EMPTY_STR = "";
String WHITESPACE_STR = " ";
String WORD_STR = "A";
String WORD_WITH_WHITESPACE_STR = " A";
System.out.println("StringUtils.isEmpty(NULL_STR) -> " + StringUtils.isEmpty(NULL_STR));
System.out.println("StringUtils.isEmpty(EMPTY_STR) -> " + StringUtils.isEmpty(EMPTY_STR));
System.out.println("StringUtils.isEmpty(WHITESPACE_STR) -> " + StringUtils.isEmpty(WHITESPACE_STR));
System.out.println("StringUtils.isEmpty(WORD_STR) -> " + StringUtils.isEmpty(WORD_STR));
System.out.println("StringUtils.isEmpty(WORD_WITH_WHITESPACE_STR) -> " + StringUtils.isEmpty(WORD_WITH_WHITESPACE_STR));
System.out.println();
System.out.println("StringUtils.isBlank(NULL_STR) -> " + StringUtils.isBlank(NULL_STR));
System.out.println("StringUtils.isBlank(EMPTY_STR) -> " + StringUtils.isBlank(EMPTY_STR));
System.out.println("StringUtils.isBlank(WHITESPACE_STR) -> " + StringUtils.isBlank(WHITESPACE_STR));
System.out.println("StringUtils.isBlank(WORD_STR) -> " + StringUtils.isBlank(WORD_STR));
System.out.println("StringUtils.isBlank(WORD_WITH_WHITESPACE_STR) -> " + StringUtils.isBlank(WORD_WITH_WHITESPACE_STR));
}
}
日志:
StringUtils.isEmpty(NULL_STR) -> true
StringUtils.isEmpty(EMPTY_STR) -> true
StringUtils.isEmpty(WHITESPACE_STR) -> false
StringUtils.isEmpty(WORD_STR) -> false
StringUtils.isEmpty(WORD_WITH_WHITESPACE_STR) -> false
StringUtils.isBlank(NULL_STR) -> true
StringUtils.isBlank(EMPTY_STR) -> true
StringUtils.isBlank(WHITESPACE_STR) -> true
StringUtils.isBlank(WORD_STR) -> false
StringUtils.isBlank(WORD_WITH_WHITESPACE_STR) -> false
摘抄API说明:
org.apache.commons.lang3.StringUtils.isEmpty(CharSequence cs) : Checks if a CharSequence is empty (“”) or null.
org.apache.commons.lang3.StringUtils.isBlank(CharSequence cs) : Checks if a CharSequence is whitespace, empty (“”) or null.
版权声明:本文为博主原创文章,未经博主允许不得转载。
Apache Commons Lang的StringUtils.isEmpty(STR)和StringUtils.isBlank(STR)的更多相关文章
- org.apache.commons.lang.StringUtils中isEmpty和isBlank的区别
public static boolean isEmpty(String str) 判断某字符串是否为空,为空的标准是str==null或str.length()==0 StringUtils.isE ...
- org.apache.commons.lang.StringUtils类
org.apache.commons.lang.StringUtils类 本文摘自:(http://www.blogjava.net/japper/archive/2012/05/23/378946. ...
- org.apache.commons.lang.StringUtils中常用的方法
org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...
- org.apache.commons.lang.StringUtils 中 Join 函数
转自 http://my.oschina.net/zenglingfan/blog/134872 写代码的时候,经常会碰到需要把一个List中的每个元素,按逗号分隔转成字符串的需求,以前是自己写一段比 ...
- org.apache.commons.lang.StringUtils的常用方法
org.apache.commons.lang.StringUtils是apache的commons-lang-x.x.jar下的包,里面包含很多字符串操作方法, 官网(http://commons. ...
- org.apache.commons.lang.StringUtils
org.apache.commons.lang.StringUtils 作为jdk中lang包的补充 检查CharSequence是否为空,null或者空格 CharSequence (CharBuf ...
- apache commons lang包中的StringUtils
计算一个字符串某个字符的出现次数 a, 使用charAt方法截取之后,循环判断. b, 使用apache commons lang包中的StringUtils: int n = StringUtils ...
- apache.commons.lang.StringUtils 使用心得
原文:http://blog.csdn.net/ye_sheng/article/details/48101901?ref=myread 在Java中我们用的最多的类应该就是String了.对于Str ...
- java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils Caused by: java.lang.ClassNotFou ...
随机推荐
- JAVA线程dump的分析
Java 的线程 线程是指能独立于程序的其它部分运行的执行单元. JAVA语言能够很好的实现多线程的程序.我们在调试程序,或者在开发后期需要做性能调优的时候,往往也需要了解当前程序正在运行的线程的状态 ...
- 如何开启firebug显示注释?
如何开启firebug注释显示?
- json(JavaScript Object Natation)学习
Json必需的包: commons-httpclient-3.1.jar commons-lang-2.4.jar commons-logging-1.1.1.jar json-lib-2.2.3-j ...
- 在jsp页面上打印错误堆栈
try{ .................... } catch(Exception e){ //定义一个流 ByteArrayOutputStream ostr = new ByteArrayOu ...
- Ubuntu 下iscsi initiator的安装与使用
Ubuntu下比较方便好用的initiator是open iscsi,这里将要简要介绍它的使用方法: 1.安装: sudo apt-get install open-iscsi 2.chap设置 如果 ...
- CSS3实现两行或三行文字,然后多出的部分省略号代替
概述 -webkit-line-clamp 是一个 不规范的属性(unsupported WebKit property),它没有出现在 CSS 规范草案中.限制在一个块元素显示的文本的行数. 为了实 ...
- SettingsEclipse&MyEclipse
eclipse优化 迁移时间--2017年5月20日09:39:16 CreateTime--2016年11月18日11:27:02 Author:Marydon ModifyTime--2017 ...
- 【DB2】db2常用SQL语句集合
持续更新中 1.修改日志模式为不记录 alter table table_name activate not logged initially; 2.清空表 alter table t1 activ ...
- lua入门之二:c/c++ 调用lua及多个函数返回值的获取
当 Lua 调用 C 函数的时候,使用和 C 调用 Lua 同样类型的栈来交互. C 函数从栈中获取她的參数.调用结束后将返回结果放到栈中.为了区分返回结果和栈中的其它的值,每一个 C 函数还会返回结 ...
- hibernate4无法保存数据
hibernate4无法保存数据 author: hiu 以后都发文章我都备注一下作者了,hiu就是我了 红色字体更新日期:2014-07-08 初次使用hibernate4,使用getCurrent ...