官方网站
http://commons.apache.org/lang/
下载地址
http://commons.apache.org/lang/download_lang.cgi
版本
commons-lang3-3.0-beta
测试方法
public static boolean isEmpty(CharSequence cs)
public static boolean isNotEmpty(CharSequence cs)
测试代码
String emptyString = "";
String nullString = null;
String blankString1 = " ";
String blankString2 = "\t\r\f\n";
String normalString = "Hello World!";
System.out.println("----------------------isEmpty------------------------------");
System.out.println("emptyString \t--> " + StringUtils.isEmpty(emptyString));
System.out.println("nullString \t--> " + StringUtils.isEmpty(nullString));
// 注意在 StringUtils 中空格作非空处理
System.out.println("blankString1 \t--> " + StringUtils.isEmpty(blankString1));
System.out.println("blankString2 \t--> " + StringUtils.isEmpty(blankString2));
System.out.println("normalString \t--> " + StringUtils.isEmpty(normalString));
System.out.println("----------------------isNotEmpty---------------------------");
System.out.println("emptyString \t--> " + StringUtils.isNotEmpty(emptyString));
System.out.println("nullString \t--> " + StringUtils.isNotEmpty(nullString));
System.out.println("blankString1 \t--> " + StringUtils.isNotEmpty(blankString1));
System.out.println("blankString2 \t--> " + StringUtils.isNotEmpty(blankString2));
System.out.println("normalString \t--> " + StringUtils.isNotEmpty(normalString));
测试结果
----------------------isEmpty---------------------------------
emptyString --> true
nullString --> true
blankString1 --> false
blankString2 --> false
normalString --> false
----------------------isNotEmpty------------------------------
emptyString --> false
nullString --> false
blankString1 --> true
blankString2 --> true
normalString --> true
测试方法
public static boolean isBlank(CharSequence cs)
public static boolean isNotBlank(CharSequence cs)
测试代码
String emptyString = "";
String nullString = null;
String blankString1 = " ";
String blankString2 = "\t\r\f\n";
String normalString = "Hello World!";
System.out.println("----------------------isBlank------------------------");
System.out.println("emptyString \t--> " + StringUtils.isBlank(emptyString));
System.out.println("nullString \t--> " + StringUtils.isBlank(nullString));
System.out.println("blankString1 \t--> " + StringUtils.isBlank(blankString1));
System.out.println("blankString2 \t--> " + StringUtils.isBlank(blankString2));
System.out.println("normalString \t--> " + StringUtils.isBlank(normalString));
System.out.println("----------------------isNotBlank----------------------");
System.out.println("emptyString \t--> " + StringUtils.isNotBlank(emptyString));
System.out.println("nullString \t--> " + StringUtils.isNotBlank(nullString));
System.out.println("blankString1 \t--> " + StringUtils.isNotBlank(blankString1));
System.out.println("blankString2 \t--> " + StringUtils.isNotBlank(blankString2));
System.out.println("normalString \t--> " + StringUtils.isNotBlank(normalString));
测试结果
----------------------isBlank------------------------
emptyString --> true
nullString --> true
blankString1 --> true
blankString2 --> true
normalString --> false
----------------------isNotBlank----------------------
emptyString --> false
nullString --> false
blankString1 --> false
blankString2 --> false
normalString --> true