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)的更多相关文章

  1. org.apache.commons.lang.StringUtils中isEmpty和isBlank的区别

    public static boolean isEmpty(String str) 判断某字符串是否为空,为空的标准是str==null或str.length()==0 StringUtils.isE ...

  2. org.apache.commons.lang.StringUtils类

    org.apache.commons.lang.StringUtils类 本文摘自:(http://www.blogjava.net/japper/archive/2012/05/23/378946. ...

  3. org.apache.commons.lang.StringUtils中常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...

  4. org.apache.commons.lang.StringUtils 中 Join 函数

    转自 http://my.oschina.net/zenglingfan/blog/134872 写代码的时候,经常会碰到需要把一个List中的每个元素,按逗号分隔转成字符串的需求,以前是自己写一段比 ...

  5. org.apache.commons.lang.StringUtils的常用方法

    org.apache.commons.lang.StringUtils是apache的commons-lang-x.x.jar下的包,里面包含很多字符串操作方法, 官网(http://commons. ...

  6. org.apache.commons.lang.StringUtils

    org.apache.commons.lang.StringUtils 作为jdk中lang包的补充 检查CharSequence是否为空,null或者空格 CharSequence (CharBuf ...

  7. apache commons lang包中的StringUtils

    计算一个字符串某个字符的出现次数 a, 使用charAt方法截取之后,循环判断. b, 使用apache commons lang包中的StringUtils: int n = StringUtils ...

  8. apache.commons.lang.StringUtils 使用心得

    原文:http://blog.csdn.net/ye_sheng/article/details/48101901?ref=myread 在Java中我们用的最多的类应该就是String了.对于Str ...

  9. java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

    java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils Caused by: java.lang.ClassNotFou ...

随机推荐

  1. 转:Python yield 使用浅析

    初学 Python 的开发者经常会发现很多 Python 函数中用到了 yield 关键字,然而,带有 yield 的函数执行流程却和普通函数不一样,yield 到底用来做什么,为什么要设计 yiel ...

  2. oracel become INDEX UNUSABLE

    1. IMPORT PARTITION or conventional path SQL*Loader. 2. Direct-path SQL*Loader leaves affected local ...

  3. java 生成可执行jar包

    jar -cvfm my.jar [配置主函数入口文件] [包] Main-Class: 包名.类名   注意“:”后边有一个空格,类名后边要有回车换行

  4. apachebench的简单使用

    apachebench的简单使用 2013-03-08 15:48:47 分类: LINUX ApacheBench是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchm ...

  5. 掀开图片显示介绍的css效果

    概述 主要运用到CSS3的3D transform等变换 详细 代码下载:http://www.demodashi.com/demo/10575.html 一.概述 1.主要运用到CSS3的3D tr ...

  6. 原创:【微信小程序】发送消息模板教程(后台以PHP示例)

    1.本教程对外开放,未经博主同意,禁止转载. 2.准备材料:1)公众号|小程序,添加选择的模板消息,2)在设置>开发设置页面,开通消息模板功能:如: 3.因为调用微信发送模板的接口是:https ...

  7. IntelliJ Idea解决Could not autowire. No beans of 'xxxx' type found的错误提示

    本文转自:http://blog.csdn.net/u012453843/article/details/54906905 1.问题描述 在Idea的spring工程里,经常会遇到Could not ...

  8. jquery ajax调用WCF,采用System.ServiceModel.WebHttpBinding

    Jquery ajax调用WCF服务 例子效果如下:原界面 点击按钮GetList get后,通过指定的Url获取数据添加到table 新建一个控制台项目,添加IContract.cs,DBServi ...

  9. Accounting_会计基础

    会计基础 1.会计:是以货币为主要计量单位,反映和监督一个单位经济活动的一种经济管理工作. 2.会计核算职能:指以货币为主要计量单位,通过确认.记录.计算.报告等环节,对特定主体的经济活动进行记账.算 ...

  10. Python ceil() 函数

    描述 ceil(x) 函数返回一个大于或等于 x 的的最小整数(向上取整). 语法 以下是 ceil() 方法的语法: import math math.ceil( x ) 注意:ceil()是不能直 ...