遇见这样一个方法,StringUtils.isNotBlank(pk) ,注释:pk 是一个参数传递值。
做个笔记,方便以后翻阅:
// StringUtils.isEmpty("")和StringUtils.isBlank("")的区别
public static void result2 (){
System.out.println("isEmpty字符串“”:"+ StringUtils.isEmpty(""));//true
System.out.println("isEmpty字符串空格“ ”:"+StringUtils.isEmpty(" "));//false
System.out.println("isEmptynull:"+StringUtils.isEmpty(null));//true
System.out.println("isEmpty字符串文字:"+StringUtils.isEmpty("字符串文字"));//false
System.out.println(" isEmpty字符串文字前后空格: "+StringUtils.isEmpty(" 字符串文字 "));//false
System.out.println("===================================================================");
System.out.println("isBlank字符串“”:"+StringUtils.isBlank(""));//true
System.out.println("isBlank字符串空格“ ”:"+StringUtils.isBlank(" "));//true
System.out.println("isBlank null:"+StringUtils.isBlank(null));//true
System.out.println("isBlank字符串文字:"+StringUtils.isBlank("字符串文字"));//fasle
System.out.println(" isBlank字符串文字前后空格: "+StringUtils.isBlank(" 字符串文字 "));//fase
}
个人总结:
StringUtils.isBlank() 它会忽略空格 ,而StringUtils.isEmpty() 把空格也当成一个字符 所有准确的说,isBlank 要isEempty 判空,要更精确。