需要导入依赖
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
我还停留在用==null判空呢,发现大家现在都用StringUtils.isBlank
判空了。。。
StringUtils.isBlank应该是没有有效文本信息,空格、制表符都为空
有时间看看这俩的源码,看看有什么区别吧
@Test
public void testNull(){
//isBlank
System.out.println(StringUtils.isBlank(null));//true
System.out.println(StringUtils.isBlank(""));//true
System.out.println(StringUtils.isBlank(" "));//true
System.out.println(StringUtils.isBlank("\t"));//true
System.out.println(StringUtils.isBlank("111"));//false
//isEmpty
System.out.println(StringUtils.isEmpty(null));//true
System.out.println(StringUtils.isEmpty(""));//true
System.out.println(StringUtils.isEmpty(" "));//false
System.out.println(StringUtils.isEmpty("\t"));//false
System.out.println(StringUtils.isEmpty("111"));//false
//==null
System.out.println(null==null);//true
System.out.println(""==null);//false
System.out.println(" "==null);//false
System.out.println("\t"==null);//false
System.out.println("111"==null);//false
}