标签:blog java ar div amp log c 字符串
针对前后含有空格、有空格的、空字符串、以及null字符的判断
public static void main(String[] args) {
String s1 = "";
String s2 = null;
String s3 = " ";
String s4 = "hello";
String s5 = " hello ";
System.out.println("1:" + isEmpty(s1));
System.out.println("2:" + isEmpty(s2));
System.out.println("3:" + isEmpty(s3));
System.out.println("4:" + isEmpty(s4));
System.out.println("5:" + isEmpty(s5));
}
public static boolean isEmpty(String str) {
str = StringUtils.trimToNull(str);
System.out.print("#" + str+"-------");
return StringUtils.isNotEmpty(str) && StringUtils.isNotBlank(str);
}
输出结果:
#null-------1:false #null-------2:false #null-------3:false #hello-------4:true #hello-------5:true
标签:blog java ar div amp log c 字符串
原文地址:http://www.cnblogs.com/lucky2u/p/3891740.html