@Test
public void test(){
String str1="";
String str2=" ";
String str3=null;
System.out.println("1" + StringUtils.isEmpty(str1)); //true
System.out.println("2" + StringUtils.isEmpty(str2)); //false
System.out.println("3" + StringUtils.isEmpty(str3)); //true
System.out.println("4" + StringUtils.isNotEmpty(str1)); //false
System.out.println("5" + StringUtils.isNotEmpty(str2)); //true
System.out.println("6" + StringUtils.isNotEmpty(str3)); //false
System.out.println("7" + StringUtils.isBlank(str1)); //true
System.out.println("8" + StringUtils.isBlank(str2)); //true
System.out.println("9" + StringUtils.isBlank(str3)); //true
System.out.println("10" + str1.isEmpty());//true
System.out.println("11" + str2.isEmpty());//false
System.out.println("12" + str3.isEmpty());//java.lang.NullPointerException
System.out.println("13" + !str1.isEmpty());//false
System.out.println("14" + !str2.isEmpty());//true
System.out.println("15" + !str3.isEmpty());//java.lang.NullPointerException
}
StringUtils来自
import org.apache.commons.lang3.StringUtils;