依赖
<!-- commons-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</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
// 判断集合中包含
String[] slist = {"a", "b", "c", "d", "e", "f", "g"};
boolean b = StringUtils.containsAny("g", slist);//true
String s1 = "123";
String s2 = "123";
//判断s1中是否包含s2
boolean contains = StringUtils.contains(s1, s2);
标签:abc,JAVA,contains,基础,containsAny,false,true,StringUtils
From: https://blog.51cto.com/u_15993308/6181577