java.lang.Object
cn.wjybxx.base.CollectionUtils
- 作者:
- wjybxx date 2023/3/31
-
字段概要
字段 -
方法概要
修饰符和类型方法说明static <E> booleanaddAll(ArrayList<E> self, Collection<? extends E> other) static intcapacity(int numMappings) 计算hash结构的默认数组大小static voidclear(Collection<?> collection) static voidstatic <E> booleancontainsCustom(List<E> list, Predicate<? super E> indexFunc) static booleancontainsRef(List<?> list, Object element) static <T> booleancontainsRef(T[] list, Object element) 判断是否存在给定元素的引用static booleandisjoint(Collection<?> source, Collection<?> candidates) 如果两个集合没有任何公共元素,则返回truestatic <E> Estatic <E> Estatic <E> Efirst(Collection<E> elements) 获取集合的首个元素static <K,V> Map.Entry <K, V> firstEntry(Map<K, V> map) static <K> Kstatic <E> EfirstOrDefault(Collection<E> collection, E def) 如果集合不为空,则返回第一个元素,否则返回默认值static <E> EfirstOrDefault(List<E> elements, E def) static <E> EgetOrDefault(List<E> elements, int index, E def) 注意:如果list包含null,且def也是null,则返回Null时无法判断是否来自集合。static <K,V> V getOrThrow(Map<K, V> map, K key) 如果给定键不存在则抛出异常static <K,V> V getOrThrow(Map<K, V> map, K key, String property) static <E> intindexOfCustom(List<E> list, Predicate<? super E> indexFunc) static intindexOfRef(List<?> list, Object element) 查找对象引用在数组中的索引static intindexOfRef(List<?> list, Object element, int startIndex) 查找对象引用在List中的索引static <T> intindexOfRef(T[] list, Object element) 查找对象引用在数组中的索引static <T> intindexOfRef(T[] list, Object element, int startIndex) 查找对象引用在数组中的索引static <K,V> Map <V, K> inverseMap(Map<K, V> src) static <K,V> Map <V, K> inverseMap(Map<K, V> src, Map<V, K> out) static booleanisEmpty(Collection<?> collection) static booleanstatic booleanjoint(Collection<?> source, Collection<?> candidates) 如果两个集合存在公共元素,则返回truestatic <E> intlastIndexOfCustom(List<E> list, Predicate<? super E> indexFunc) static intlastIndexOfRef(List<?> list, Object element) 反向查找对象引用在List中的索引static intlastIndexOfRef(List<?> list, Object element, int startIndex) 反向查找对象引用在List中的索引static <T> intlastIndexOfRef(T[] list, Object element) 反向查找对象引用在数组中的索引static <T> intlastIndexOfRef(T[] list, Object element, int startIndex) 反向查找对象引用在数组中的索引static <E> ElastOrDefault(List<E> elements, E def) static <E> ArrayList<E> newArrayList(E a) static <E> ArrayList<E> newArrayList(E a, E b) static <E> ArrayList<E> newArrayList(E a, E b, E c) static <E> DelayedCompressList<E> static <E> DelayedCompressList<E> newDelayedCompressList(int initCapacity) static <E> DelayedCompressList<E> newDelayedCompressList(Collection<? extends E> src) static <K,V> HashMap <K, V> newHashMap(int size) 创建一个能存储指定元素数量的HashMapstatic <K,V> HashMap <K, V> newHashMap(K k, V v) 创建一个包含初始kv的HashMapstatic <K,V> HashMap <K, V> newHashMap(K k, V v, K k2, V v2) static <E> HashSet<E> newHashSet(int size) static <K,V> IdentityHashMap <K, V> newIdentityHashMap(int size) static <E> Set<E> newIdentityHashSet(int size) static <K,V> LinkedHashMap <K, V> newLinkedHashMap(int size) 创建一个能存储指定元素数量的LinkedHashMapstatic <K,V> LinkedHashMap <K, V> newLinkedHashMap(K k, V v) 创建一个包含初始kv的LinkedHashMapstatic <K,V> LinkedHashMap <K, V> newLinkedHashMap(K k, V v, K k2, V v2) static <E> LinkedHashSet<E> newLinkedHashSet(int size) static <E> List<E> nullToArrayList(List<E> src) 如果列表为Null,则返回空数组列表static <E> List<E> nullToEmptyList(List<E> src) 如果列表为Null,则返回空列表static <E> booleanremoveAll(ArrayList<E> self, Collection<? extends E> other) static <E> E删除指定位置的元素,可以选择是否保持列表中元素的顺序,当不需要保持顺序时可以对删除性能进行优化 注意:应当小心使用该特性,能够使用该特性的场景不多,应当慎之又慎。static <E> booleanremoveFirstMatch(Collection<E> collection, Predicate<? super E> predicate) 移除集合中第一个匹配的元素static <E> booleanremoveFirstMatch(List<E> list, Predicate<? super E> predicate) 移除list中第一个匹配的元素 -- 最好是数组列表static voidremoveFirstN(List<?> list, int n) 删除list的前n个元素static <E> booleanremoveLastMatch(List<E> list, Predicate<? super E> predicate) 移除List中最后一个匹配的元素 -- 最好是数组列表static voidremoveLastN(List<?> list, int n) 删除list的后n个元素static booleanremoveRef(Collection<?> collection, Object element) 使用“==”删除第一个匹配的元素static boolean使用“==”删除对象static boolean使用“==”删除对象static <T> Stream<T> Converts interable to a non-parallel stream.static <T> Stream<T> Converts iterator to a stream.static <E> ArrayList<E> toArrayList(E[] array) static <E> ArrayList<E> toArrayList(E[] array, int offset, int length) toImmutableEnumMap(Map<K, V> src, Class<K> keyType) 转换为不可变的EnumMap,用于需要保持高效查询的场景toImmutableEnumSet(Collection<E> src, Class<E> keyType) 转换为不可变的EnumSet,用户需要保持高效查询效率的场景static <K,V> Map <K, V> toImmutableLinkedHashMap(Map<K, V> src) 转换为不可变的LinkedHashMap,通常用于需要保留Key的顺序的场景static <E> Set<E> toImmutableLinkedHashSet(Collection<E> src) 转换为不可变的LinkedHashSet,用于需要保持元素顺序的场景static <E> List<E> toImmutableList(Collection<E> src) static <E> List<E> toImmutableList(Collection<E> src, Comparator<? super E> comparator) static <K,V> Map <K, V> toImmutableMap(Map<K, V> src) toImmutableMultiEnumMap(Map<K, ? extends Collection<V>> src, Class<K> keyType) 转换为不可变的EnumMap,用于需要保持高效查询的场景toImmutableMultiLinkedHashMap(Map<K, ? extends Collection<V>> src) 转换为不可变的LinkedHashMap,通常用于需要保留Key的顺序的场景toImmutableMultiMap(Map<K, ? extends Collection<V>> src) static <E> Set<E> toImmutableSet(Collection<E> src) static <E> List<E> toList(E[] array) static <E> List<E> toList(E[] array, int offset, int length) static <E> List<E> 连接列表static <E> List<E> 连接多个列表static <E> intunorderedRemoveIf(List<E> list, Predicate<? super E> filter) 删除满足条件的元素,且不保持列表中元素的顺序 -- 慎用该方法。
-
字段详细资料
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUND- 另请参阅:
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY -
EMPTY_INT_ARRAY
public static final int[] EMPTY_INT_ARRAY -
EMPTY_LONG_ARRAY
public static final long[] EMPTY_LONG_ARRAY -
EMPTY_FLOAT_ARRAY
public static final float[] EMPTY_FLOAT_ARRAY -
EMPTY_DOUBLE_ARRAY
public static final double[] EMPTY_DOUBLE_ARRAY -
EMPTY_BOOLEAN_ARRAY
public static final boolean[] EMPTY_BOOLEAN_ARRAY -
EMPTY_STRING_ARRAY
-
EMPTY_OBJECT_ARRAY
-
EMPTY_CLASS_ARRAY
-
-
方法详细资料
-
newDelayedCompressList
-
newDelayedCompressList
-
newDelayedCompressList
-
getOrDefault
注意:如果list包含null,且def也是null,则返回Null时无法判断是否来自集合。 -
firstOrDefault
-
lastOrDefault
-
removeFirstN
删除list的前n个元素 -
removeLastN
删除list的后n个元素 -
removeFirstMatch
移除list中第一个匹配的元素 -- 最好是数组列表 -
removeLastMatch
移除List中最后一个匹配的元素 -- 最好是数组列表 -
removeAt
删除指定位置的元素,可以选择是否保持列表中元素的顺序,当不需要保持顺序时可以对删除性能进行优化 注意:应当小心使用该特性,能够使用该特性的场景不多,应当慎之又慎。- 参数:
ordered- 是否保持之前的顺序。- 返回:
- 删除的元素
-
unorderedRemoveIf
删除满足条件的元素,且不保持列表中元素的顺序 -- 慎用该方法。- 返回:
- 删除的元素个数
-
indexOfCustom
- 参数:
list- 最好为数组列表
-
lastIndexOfCustom
- 参数:
list- 最好为数组列表
-
containsCustom
- 参数:
list- 最好为数组列表
-
findFirst
- 参数:
list- 最好为数组列表
-
findLast
- 参数:
list- 最好为数组列表
-
containsRef
-
indexOfRef
查找对象引用在数组中的索引 -
indexOfRef
查找对象引用在List中的索引- 参数:
element- 要查找的元素startIndex- 开始下标
-
lastIndexOfRef
反向查找对象引用在List中的索引 -
lastIndexOfRef
反向查找对象引用在List中的索引- 参数:
element- 要查找的元素startIndex- 开始下标
-
removeRef
使用“==”删除对象 -
removeRef
使用“==”删除对象 -
containsRef
判断是否存在给定元素的引用 -
indexOfRef
查找对象引用在数组中的索引 -
indexOfRef
查找对象引用在数组中的索引- 参数:
element- 要查找的元素startIndex- 开始下标
-
lastIndexOfRef
反向查找对象引用在数组中的索引 -
lastIndexOfRef
反向查找对象引用在数组中的索引- 参数:
element- 要查找的元素startIndex- 开始下标
-
newArrayList
-
newArrayList
-
newArrayList
-
addAll
-
removeAll
-
toList
-
toList
-
toArrayList
-
toArrayList
-
union
连接列表 -
union
@SafeVarargs public static <E> List<E> union(List<E> first, List<? extends E> second, List<E>... more) 连接多个列表 -
toImmutableList
-
toImmutableList
@Nonnull public static <E> List<E> toImmutableList(@Nullable Collection<E> src, Comparator<? super E> comparator) - 参数:
comparator- 在转换前进行一次排序
-
nullToArrayList
如果列表为Null,则返回空数组列表 -
nullToEmptyList
如果列表为Null,则返回空列表 -
newHashSet
- 另请参阅:
-
newLinkedHashSet
- 另请参阅:
-
newIdentityHashSet
-
toImmutableSet
-
toImmutableLinkedHashSet
转换为不可变的LinkedHashSet,用于需要保持元素顺序的场景 -
toImmutableEnumSet
public static <E extends Enum<E>> Set<E> toImmutableEnumSet(@Nullable Collection<E> src, Class<E> keyType) 转换为不可变的EnumSet,用户需要保持高效查询效率的场景 -
newHashMap
创建一个能存储指定元素数量的HashMap- 另请参阅:
-
newHashMap
创建一个包含初始kv的HashMap -
newHashMap
-
newLinkedHashMap
创建一个能存储指定元素数量的LinkedHashMap- 另请参阅:
-
newLinkedHashMap
创建一个包含初始kv的LinkedHashMap -
newLinkedHashMap
-
newIdentityHashMap
-
getOrThrow
如果给定键不存在则抛出异常 -
getOrThrow
-
firstKey
- 抛出:
NoSuchElementException- 如果map为空
-
firstEntry
- 抛出:
NoSuchElementException- 如果map为空
-
inverseMap
-
inverseMap
-
toImmutableMap
- 参数:
src- 不支持key或value为null
-
toImmutableMultiMap
@Nonnull public static <K,V> Map<K,List<V>> toImmutableMultiMap(@Nullable Map<K, ? extends Collection<V>> src) - 参数:
src- 不支持key或value为null
-
toImmutableLinkedHashMap
转换为不可变的LinkedHashMap,通常用于需要保留Key的顺序的场景 -
toImmutableMultiLinkedHashMap
@Nonnull public static <K,V> Map<K,List<V>> toImmutableMultiLinkedHashMap(@Nullable Map<K, ? extends Collection<V>> src) 转换为不可变的LinkedHashMap,通常用于需要保留Key的顺序的场景 -
toImmutableEnumMap
@Nonnull public static <K extends Enum<K>,V> Map<K,V> toImmutableEnumMap(@Nullable Map<K, V> src, Class<K> keyType) 转换为不可变的EnumMap,用于需要保持高效查询的场景 -
toImmutableMultiEnumMap
@Nonnull public static <K extends Enum<K>,V> Map<K,List<V>> toImmutableMultiEnumMap(@Nullable Map<K, ? extends Collection<V>> src, Class<K> keyType) 转换为不可变的EnumMap,用于需要保持高效查询的场景 -
isEmpty
-
isEmpty
-
clear
-
clear
-
joint
如果两个集合存在公共元素,则返回true -
disjoint
如果两个集合没有任何公共元素,则返回true -
first
获取集合的首个元素 -
firstOrDefault
如果集合不为空,则返回第一个元素,否则返回默认值 -
removeFirstMatch
public static <E> boolean removeFirstMatch(Collection<E> collection, Predicate<? super E> predicate) 移除集合中第一个匹配的元素- 类型参数:
E- 集合中的元素类型- 参数:
collection- 可修改的集合predicate- 删除条件,为true的删除。- 返回:
- 是否成功删除了一个元素
-
removeRef
使用“==”删除第一个匹配的元素 -
streamOf
Converts iterator to a stream. -
streamOf
Converts interable to a non-parallel stream. -
capacity
public static int capacity(int numMappings) 计算hash结构的默认数组大小
-