Package cn.com.anysdk.core.util
Class CollectionUtils
java.lang.Object
cn.com.anysdk.core.util.CollectionUtils
集合工具类
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontains(Collection<?> collection, Object element) 判断集合是否包含指定元素static booleancontainsAll(Collection<?> collection, Collection<?> elements) 判断集合是否包含所有指定元素static booleancontainsAny(Collection<?> collection, Collection<?> elements) 判断集合是否包含任一指定元素static <T> List<T> filter(Collection<T> collection, Predicate<T> predicate) 过滤集合static <T> Tfirst(Collection<T> collection) 获取集合的第一个元素groupBy(Collection<T> collection, Function<T, K> classifier) 将集合按指定条件分组groupBy(Collection<T> collection, Function<T, K> classifier, Function<T, V> valueMapper) 将集合按指定条件分组并转换值static <T> Collection<T> intersection(Collection<T> a, Collection<T> b) 获取集合的交集static booleanisEmpty(Collection<?> collection) 判断集合是否为空static boolean判断Map是否为空static booleanisNotEmpty(Collection<?> collection) 判断集合是否不为空static booleanisNotEmpty(Map<?, ?> map) 判断Map是否不为空static <T> Tlast(Collection<T> collection) 获取集合的最后一个元素static <T,R> List <R> map(Collection<T> collection, Function<T, R> mapper) 转换集合static <T> Trandom(Collection<T> collection) 获取集合的随机元素static <T> List<T> random(Collection<T> collection, int count) 获取集合的随机元素(指定数量)static intsize(Collection<?> collection) 获取集合大小static int获取Map大小static <T> Collection<T> subtract(Collection<T> a, Collection<T> b) 获取集合的差集static <T> List<T> toList(Collection<T> collection) 将集合转换为Liststatic <T,K> Map <K, T> toMap(Collection<T> collection, Function<T, K> keyMapper) 将集合转换为Map(值相同)static <T,K, V> Map <K, V> toMap(Collection<T> collection, Function<T, K> keyMapper, Function<T, V> valueMapper) 将集合转换为Mapstatic <T> Set<T> toSet(Collection<T> collection) 将集合转换为Setstatic <T> Collection<T> union(Collection<T> a, Collection<T> b) 获取集合的并集
-
Method Details
-
isEmpty
判断集合是否为空- Parameters:
collection- 集合- Returns:
- 是否为空
-
isNotEmpty
判断集合是否不为空- Parameters:
collection- 集合- Returns:
- 是否不为空
-
isEmpty
判断Map是否为空- Parameters:
map- Map- Returns:
- 是否为空
-
isNotEmpty
判断Map是否不为空- Parameters:
map- Map- Returns:
- 是否不为空
-
size
获取集合大小- Parameters:
collection- 集合- Returns:
- 大小
-
size
获取Map大小- Parameters:
map- Map- Returns:
- 大小
-
contains
判断集合是否包含指定元素- Parameters:
collection- 集合element- 元素- Returns:
- 是否包含
-
containsAll
判断集合是否包含所有指定元素- Parameters:
collection- 集合elements- 元素集合- Returns:
- 是否包含所有
-
containsAny
判断集合是否包含任一指定元素- Parameters:
collection- 集合elements- 元素集合- Returns:
- 是否包含任一
-
intersection
获取集合的交集- Parameters:
a- 集合ab- 集合b- Returns:
- 交集
-
union
获取集合的并集- Parameters:
a- 集合ab- 集合b- Returns:
- 并集
-
subtract
获取集合的差集- Parameters:
a- 集合ab- 集合b- Returns:
- 差集
-
toList
将集合转换为List- Parameters:
collection- 集合- Returns:
- List
-
toSet
将集合转换为Set- Parameters:
collection- 集合- Returns:
- Set
-
toMap
public static <T,K, Map<K,V> V> toMap(Collection<T> collection, Function<T, K> keyMapper, Function<T, V> valueMapper) 将集合转换为Map- Parameters:
collection- 集合keyMapper- 键映射函数valueMapper- 值映射函数- Returns:
- Map
-
toMap
将集合转换为Map(值相同)- Parameters:
collection- 集合keyMapper- 键映射函数- Returns:
- Map
-
groupBy
将集合按指定条件分组- Parameters:
collection- 集合classifier- 分组函数- Returns:
- 分组后的Map
-
groupBy
public static <T,K, Map<K,V> List<V>> groupBy(Collection<T> collection, Function<T, K> classifier, Function<T, V> valueMapper) 将集合按指定条件分组并转换值- Parameters:
collection- 集合classifier- 分组函数valueMapper- 值映射函数- Returns:
- 分组后的Map
-
filter
过滤集合- Parameters:
collection- 集合predicate- 过滤条件- Returns:
- 过滤后的集合
-
map
转换集合- Parameters:
collection- 集合mapper- 转换函数- Returns:
- 转换后的集合
-
first
获取集合的第一个元素- Parameters:
collection- 集合- Returns:
- 第一个元素
-
last
获取集合的最后一个元素- Parameters:
collection- 集合- Returns:
- 最后一个元素
-
random
获取集合的随机元素- Parameters:
collection- 集合- Returns:
- 随机元素
-
random
获取集合的随机元素(指定数量)- Parameters:
collection- 集合count- 数量- Returns:
- 随机元素集合
-