containsAll

This commit is contained in:
duhanmin
2022-07-09 11:32:55 +08:00
parent c7db8b2e16
commit 607ddb725e
2 changed files with 28 additions and 0 deletions

View File

@@ -1006,6 +1006,26 @@ public class CharSequenceUtil {
return true;
}
/**
* 检查指定字符串中是否含给定的所有字符串
*
* @param str 字符串
* @param testChars 检查的字符
* @return 字符串含有非检查的字符返回false
* @since 4.4.1
*/
public static boolean containsAll(CharSequence str, CharSequence... testChars) {
if (isBlank(str) || ArrayUtil.isEmpty(testChars)) {
return false;
}
for (CharSequence testChar : testChars) {
if (false == contains(str, testChar)) {
return false;
}
}
return true;
}
/**
* 给定字符串是否包含空白符(空白符包括空格、制表符、全角空格和不间断空格)<br>
* 如果给定字符串为null或者""则返回false

View File

@@ -611,4 +611,12 @@ public class StrUtilTest {
String a = "2142342422423423";
Assert.assertTrue(StrUtil.isNumeric(a));
}
@Test
public void containsAllTest() {
String a = "2142342422423423";
Assert.assertTrue(StrUtil.containsAll(a, "214", "234"));
}
}