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 ...
随机推荐
- VB LISTBOX属性
additem 添加属性 listcount总记录数 listindex索引值 Private Sub Form_Load()List1.AddItem "广东省广州市"List1 ...
- webservice系统学习笔记7-异常处理
接口类:IMyService.java @WebResult(name="testExceptionResult") public void testException() thr ...
- VC 线程间通信的三种方式
1.使用全局变量(窗体不适用) 实现线程间通信的方法有很多,常用的主要是通过全局变量.自定义消息和事件对象等来实现的.其中又以对全局变量的使用最为简洁.该方法将全局变量作为线程监视的对象,并通 ...
- 用JSON-server模拟REST API
来源于: 用JSON-server模拟REST API(一) 安装运行 用JSON-server模拟REST API(二) 动态数据 用JSON-server模拟REST API(三) 进阶使用 在开 ...
- aop注解 自定义切面的注解写法
spring.xml中 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...
- 【转载】spring mvc 使用session
http://home.51.com/gaoyangboy/diary/item/10036382.html Spring2.5 访问 Session 属性的四种策略 Posted on 2008-1 ...
- editplus发布3.01 Build 446 Final版(附下载及中文版)
http://www.cnblogs.com/JustinYoung/archive/2008/04/14/editplus-301.html没有什么好说的,我个人最喜欢的编辑器.除了windows和 ...
- evernote如何笔记共享
首先将你的笔记共享 访问你的共享笔记地址,就可看到共享笔记的内容了 https://www.evernote.com/pub/用户名/笔记名 https://www.evernote.com/ ...
- 利用C#改写JAVA中的Base64.DecodeBase64以及Inflater解码
最近正在进行项目服务的移植工作,即将JAVA服务的程序移植到DotNet平台中. 在JAVA程序中,有个HTTP请求数据头中,包含一个BASE64编码的字符串,例如: eJyVjMENgDAMA1fp ...
- JAVA RMI远程方法调用简单实例[转]
RMI的概念 RMI(Remote Method Invocation)远程方法调用是一种计算机之间利用远程对象互相调用实现双方通讯的一种通讯机制.使用这种机制,某一台计算机上的对象可以调用另外 一台 ...