如果你的项目是maven工程,首先在pom.xml中添加commons-lang3包的依赖
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
是否包含某个字符
import org.apache.commons.lang3.StringUtils;
StringUtils.contains("abc", "") = true
StringUtils.contains("abc", "a") = true
StringUtils.contains("abc", "A") = true
StringUtils.contains("abc", 'a') = true
StringUtils.contains("abc", 'z') = false
//检查字符序列(CharSequence)是否包含给定数组中的任何字符序列
//boolean containsAny(final CharSequence cs, final char... searchChars)
StringUtils.containsAny("zzabyycdxx", "za") = true
StringUtils.containsAny("zzabyycdxx", "by") = true
StringUtils.containsAny("abcd", "ab", "cd") = true
StringUtils.containsAny("abc", "d", "abc") = true
StringUtils.containsAny("zzabyycdxx",'z','a') = true
StringUtils.containsAny("zzabyycdxx",'b','y') = true
StringUtils.containsAny("aba", 'z') = false
//检查字符序列(CharSequence)是否只包含某些字符
//boolean containsOnly(final CharSequence cs, final char... valid)
StringUtils.containsOnly("ab", '') = false
StringUtils.containsOnly("abab", 'abc') = true
StringUtils.containsOnly("ab1", 'abc') = false
StringUtils.containsOnly("abz", 'abc') = false
//检查字符序列(CharSequence)不包含某些字符
//boolean containsNone(final CharSequence cs, final char... searchChars)
StringUtils.containsNone("ab","") = true
StringUtils.containsNone("abab","xyz") = true
StringUtils.containsNone("ab1", "xyz") = true
StringUtils.containsNone("abz", "xyz") = false
//检查字符序列是否以指定的前缀开始
StringUtils.startsWith("abcdef", null) = false
StringUtils.startsWith("abcdef", "abc") = true
StringUtils.startsWith("ABCDEF", "abc") = false