导入依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.0.7</version>
</dependency>
StrUtil类,对字符串进行处理的工具类。
hasBlank、hasEmpty方法都是用来判断字符串是否为空的
@Test
//判断字符串是否为空
public void hasBlankOrhasEmptyTest(){
String str1 = " ";
String str2 = "";
System.out.println(StrUtil.hasBlank(str1));
System.out.println(StrUtil.hasBlank(str2));
System.out.println(StrUtil.hasEmpty(str1));
System.out.println(StrUtil.hasEmpty(str2));
}
结果
true
true
false
true
- hasEmpty方法只能判断为null和空字符串(""),而hasBlank方法还会将不可见字符也视为空。
- removePrefix、removeSuffix分别用于去除字符串的指定前缀和后缀。
- 参考文档 https://blog.csdn.net/u012796085/article/details/104068911
- hutool官网文档