Package icu.easyj.core.util
Class CollectionUtils
java.lang.Object
icu.easyj.core.util.MapUtils
icu.easyj.core.util.CollectionUtils
集合工具类
- Author:
- wangliang181230
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Collection<?>>
TdefaultIfEmpty(T coll, Supplier<T> defaultValueSupplier) 如果为空数组,则执行supplier生成新的值static <T extends Collection<?>>
TdefaultIfEmpty(T coll, T defaultValue) 如果为空集合,则取默认值static <T> T获取列表的第一项,并保证线程安全。static <T> T获取列表的最后一项,并保证线程安全。static booleanisEmpty(Collection<?> coll) 判断集合是否为空static booleanisNotEmpty(Collection<?> coll) 判断集合是否不为空static StringtoString(Collection<?> col) Collection To String.Methods inherited from class icu.easyj.core.util.MapUtils
computeIfAbsent, defaultIfEmpty, defaultIfEmpty, isEmpty, isNotEmpty, quickMap, quickMap, quickMap, toMap, toMap, toString
-
Constructor Details
-
CollectionUtils
public CollectionUtils()
-
-
Method Details
-
getFirst
获取列表的第一项,并保证线程安全。- Type Parameters:
T- 列表项的类型- Parameters:
list- 列表- Returns:
- lastItem 返回列表的第一项
-
getLast
获取列表的最后一项,并保证线程安全。存在线程安全问题的原因:`list.size()` 和 `list.get(size - 1)` 两个方法不是原子操作。
注意:即使 `List` 本身是线程安全的,也会存在该问题。
- Type Parameters:
T- 列表项的类型- Parameters:
list- 列表- Returns:
- lastItem 返回列表的最后一项
-
isEmpty
判断集合是否为空- Parameters:
coll- 集合- Returns:
- 是否为空
-
isNotEmpty
判断集合是否不为空- Parameters:
coll- 集合- Returns:
- 是否不为空
-
defaultIfEmpty
如果为空集合,则取默认值- Type Parameters:
T- 集合类型- Parameters:
coll- 集合defaultValue- 默认值- Returns:
- 入参集合或默认值
-
defaultIfEmpty
如果为空数组,则执行supplier生成新的值- Type Parameters:
T- 集合类型- Parameters:
coll- 集合defaultValueSupplier- 默认值提供者- Returns:
- 入参集合或生成的默认值
-
toString
Collection To String.- Parameters:
col- 集合- Returns:
- str 字符串
-