public abstract class CollectionUtils extends MapUtils
| 构造器和说明 |
|---|
CollectionUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends Collection<?>> |
defaultIfEmpty(T coll,
Supplier<T> defaultValueSupplier)
如果为空数组,则执行supplier生成新的值
|
static <T extends Collection<?>> |
defaultIfEmpty(T coll,
T defaultValue)
如果为空集合,则取默认值
|
static <T> T |
getFirst(List<T> list)
获取列表的第一项,并保证线程安全。
|
static <T> T |
getLast(List<T> list)
获取列表的最后一项,并保证线程安全。
|
static boolean |
isEmpty(Collection<?> coll)
判断集合是否为空
|
static boolean |
isNotEmpty(Collection<?> coll)
判断集合是否不为空
|
static String |
toString(Collection<?> col)
Collection To String.
|
computeIfAbsent, isEmpty, isNotEmpty, toString@NonNull public static String toString(Collection<?> col)
col - 集合@Nullable public static <T> T getFirst(List<T> list)
T - 列表项的类型list - 列表@Nullable public static <T> T getLast(List<T> list)
存在线程安全问题的原因:`list.size()` 和 `list.get(size - 1)` 两个方法不是原子操作。
注意:即使 `List` 本身是线程安全的,也会存在该问题。
T - 列表项的类型list - 列表public static boolean isEmpty(Collection<?> coll)
coll - 集合public static boolean isNotEmpty(Collection<?> coll)
coll - 集合public static <T extends Collection<?>> T defaultIfEmpty(T coll, T defaultValue)
T - 集合类型coll - 集合defaultValue - 默认值public static <T extends Collection<?>> T defaultIfEmpty(T coll, Supplier<T> defaultValueSupplier)
T - 集合类型coll - 集合defaultValueSupplier - 默认值提供者Copyright © 2021 EasyJ寮�婧愮ぞ鍖�. All rights reserved.