Merge pull request #1926 from HbnKing/v5-dev

add  method
This commit is contained in:
Golden Looly 2021-11-02 23:31:23 +08:00 committed by GitHub
commit c663713680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -414,12 +414,31 @@ public class CollUtil {
* @param collection 集合
* @param value 需要查找的值
* @return 如果集合为空null或者空返回{@code false}否则找到元素返回{@code true}
* @throws ClassCastException 如果类型不一致会抛出转换异常
* @throws NullPointerException 当指定的元素 值为 null ,或集合类不支持null 时抛出该异常
* @see Collection#contains(Object)
* @since 4.1.10
*/
public static boolean contains(Collection<?> collection, Object value) {
return isNotEmpty(collection) && collection.contains(value);
}
/**
* 判断指定集合是否包含指定值如果集合为空null或者空返回{@code false}否则找到元素返回{@code true}
* @param collection 集合
* @param value 需要查找的值
* @return 果集合为空null或者空返回{@code false}否则找到元素返回{@code true}
*/
public static boolean safeContains(Collection<?> collection, Object value) {
try {
return contains(collection ,value);
} catch (ClassCastException | NullPointerException e) {
return false;
}
}
/**
* 自定义函数判断集合是否包含某类值
*