String类型判空、

针对前后含有空格、有空格的、空字符串、以及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

  

posted @ 2014-08-05 10:51  拔丝苹果皮  阅读(267)  评论(0编辑  收藏  举报