接口地址
http://commons.apache.org/proper/commons-lang/javadocs/api-3.9/
包
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
字符串
判断字符串 不为空和null
StringUtils.isNotEmpty(xxxx)
移除两边空字符串
StringUtils.trim(xxxx)
移除空格
StringUtils.deleteWhitespace(xxxx)
移除指定开头字符
StringUtils.removeStart("www.foxwho.com","www.foxwho")
删除指定字符串
StringUtils.strip(xxxx)
字符串对比
StringUtils.equals(null, null)
忽略大小写
StringUtils.equalsIgnoreCase(null, null)
字符位置
StringUtils.indexOf("XX", "X")
字符串包含
StringUtils.contains("XX", "X")
判断字符串是否以指定的字符序列数组中任意一个开头,区分大小写:
StringUtils.startsWithAny(null, null);// false
StringUtils.startsWithAny(null, new String[] { "abc" });// false
StringUtils.startsWithAny("abcxyz", null);// false
StringUtils.startsWithAny("abcxyz", new String[] { "" });// true
StringUtils.startsWithAny("abcxyz", new String[] { "abc" });// true
StringUtils.startsWithAny("abcxyz", new String[] { null, "xyz", "abc" });// true
StringUtils.startsWithAny("abcxyz", null, "xyz", "ABCX");// false
StringUtils.startsWithAny("ABCXYZ", null, "xyz", "abc");// false
字符串截取
StringUtils.substring("XX", "X")
字符串分割成数组
StringUtils.split("XX=X")
数组拆分成字符串
StringUtils.join(["XX", "X"])
字符串自动补齐
右补齐
StringUtils.rightPad("23",5,"0");
结果
23000
左补齐
StringUtils.leftPad("23",5,"0");
结果
00023
中部补齐
StringUtils.center(String str,int size,String padStr);
首字母大写
StringUtils.capitalize()
反向大写 StringUtils.swapCase
判断是否字母
StringUtils.isAlpha
字符串翻转
StringUtils.reverse
忽略字符串
StringUtils.abbreviate
字符串包装
StringUtils.wrap
数组
数组中是否包含字符串,数组中是否存在指定的元素
import org.apache.commons.lang3.ArrayUtils;
String[] arr=new String[]{"aaa","bbbb","cccc"}
String value="cccc";
ArrayUtils.contains(arr,value);
不要使用 arrays.aslist(arr).contains(value)
部分来源:
https://blog.csdn.net/qq_39964694/article/details/80334556