JAVA-判断字符串是否为空,只有空格也算空。

/**
	 * 判断字符串是否为空
	 * @param str
	 * @return
	 */
	public static boolean isEmpty(String str) {
		if(str != null && !str.replace(" ", "").equals("")){
			return false;
		}
		else {
			return true;
		}
	}
	
	public static void main(String[] args) {
		System.out.println(isEmpty("        "));
	}

上面工具类用来判断字符串是否为空,只有空格也算空。

猜你喜欢

转载自blog.csdn.net/jiaowohaohao/article/details/105305830