总结不全,后续会慢慢添加
详见官方文档
StringUtils是JDK提供的String类型操作方法的补充,并且是 null 安全的(即如果输入参数 String 为 null 则不会抛出 NullPointerException ,而是做了相应处理,例如,如果输入为 null 则返回也是 null 等,具体可以查看源代码)。
除了构造器,StringUtils 中一共有130多个方法,并且都是 static 的,所以我们可以这样调用 StringUtils.xxx()
引入的jar文件
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
isEmpty
package com.example.demo.util;
import org.apache.commons.lang3.StringUtils;
/**
* @description: 操作String类型的工具
* @create: 2020/03/15 20:42
**/
public class StringUtil {
public static void main(String[] args) {
isEmpty();
}
/**
* isEmpty() 判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0
* 注意:在StringUtils中空格作非空处理,即String str = " "; str.length()=1,不为空
*/
public static void 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(" ")); //false
System.out.println(StringUtils.isEmpty("bob")); //false
System.out.println(StringUtils.isEmpty(" bob ")); //false
}
}
isNotEmpty
package com.example.demo.util;
import org.apache.commons.lang3.StringUtils