public final class CollectionUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static List |
EMPTY_LIST
空列表
|
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> void |
addAll(Collection<T> collection,
Collection<T> addCollection)
添加所有的元素
|
static <T> void |
addArray(Collection<T> collection,
T[] array)
将数组的内容添加到集合
|
static <T> List<T> |
append(List<T> list,
T t)
添加元素到列表
|
static List<String> |
arrayToList(String[] array)
根据数组返回对应列表
|
static <T,R> Collection<R> |
buildCollection(Collection<T> targets,
IHandler<T,R> handler)
构建结果集合
1.
|
static <T,R> List<R> |
buildCollection(T[] targets,
IHandler<T,R> handler)
构建结果集合
1.
|
static <T> List<T> |
conditionList(Collection<T> list,
ICondition<T> condition)
执行列表过滤
|
static boolean |
containAny(Collection<String> firstList,
Collection<String> secondList)
包含任何一个
|
static boolean |
contains(Collection<?> collection,
Object value)
是否包含
|
static <T> List<T> |
copy(List<T> list)
复制列表
|
static <E> List<E> |
difference(Collection<E> collectionOne,
Collection<E> collectionTwo)
集合的差集
|
static <T> List<T> |
distinct(Collection<T> collection)
去重集合
|
static <T extends Comparable> |
distinctAndSort(Collection<T> collection)
去重并且排序
|
static List<Integer> |
fill(int size)
填充信息
|
static <E> List<E> |
fill(int size,
E elem)
填充信息
|
static List<Integer> |
fill(int size,
int initValue)
填充信息
|
static <E> List<E> |
fillList(List<E> values,
IFiller<E> filler)
遍历填充对象
|
static <T> List<T> |
filterList(Collection<T> list,
IFilter<T> filter)
执行列表过滤
|
static <T> Optional<T> |
firstNotNullElem(Collection<T> list)
找到第一个不为 null 的元素
|
static <E> void |
foreach(Collection<E> collection,
IHandler<E,Void> handler)
循环处理集合
|
static <E> void |
foreachPrint(Collection<E> collection)
循环处理集合
|
static int |
getEndIndex(int endIndex,
Collection<?> collection)
获取开始的下标
(1)默认为0
(2)如果为负数,或者超过 arrays.length-1,则使用 arrays.length-1
(3)正常返回 endIndex
|
static <E> E |
getFirst(Collection<E> collection)
获取第一个元素
1.
|
static String |
getLast(List<String> resultList)
获取最后一行
|
static <T extends Comparable> |
getRepeatList(Collection<T> collection)
获取重复列表
|
static int |
getStartIndex(int startIndex,
Collection<?> collection)
获取开始的下标
(1)默认为0
(2)如果为负数,或者超过 arrays.length-1,则使用 0
(3)正常返回 startIndex
|
static <T> List<T> |
getTopK(Collection<T> collection,
int size)
获取指定的前几个元素
|
static <T> T |
head(List<T> list)
获取第一个元素
|
static <E> List<E> |
interSection(Collection<E> collectionOne,
Collection<E> collectionTwo)
集合的差交集
|
static boolean |
isEmpty(Collection collection)
是否为空
|
static boolean |
isNotEmpty(Collection collection)
是否不为空
|
static String |
join(Collection<?> stringCollection)
将字符串集合内容按照逗号连接起来
|
static String |
join(Collection<?> stringCollection,
String connector)
将字符串集合内容按照 connector 连接起来
|
static <T> List<T> |
list()
空列表
|
static <T> List<T> |
list(T... ts)
列表
|
static <T> List<T> |
list(T t)
空列表
|
static String[] |
listToArray(List<String> stringList)
列表转数组
|
static <T> List<T> |
pageList(Collection<T> collection,
int pageNum,
int pageSize)
内存分页
ps: 类似 mysql 的分页模式,性能越往后越差。
|
static <T> List<T> |
pageList(List<T> list,
int pageNum,
int pageSize)
内存分页
|
static <T> T |
random(Collection<T> collection)
随机一个元素
loop 实现,性能比较差
|
static <E> E |
random(List<E> list)
随机获取一个元素
|
static List<String> |
replaceAll(Collection<String> collection,
String regex,
String target)
针对整个集合做替换处理
|
static <T> List<T> |
reverse(List<T> list,
T t)
反转列表
|
static void |
setLast(List<String> resultList,
String line)
设置最后一行
|
static <T extends Comparable> |
sort(List<T> collection)
排序
|
static List<String> |
splitByAnyBlank(String string)
按照任意空格拆分
|
static <E> List<E> |
subList(List<E> list,
int offset,
int limit)
对原始列表进行截取
|
static <T> T |
tail(List<T> list)
获取最后一个元素
|
static <K,V> List<K> |
toList(Iterable<V> values,
IHandler<? super V,K> keyFunction)
可遍历的元素对象的某个元素,转换为列表
|
static <K,V> List<K> |
toList(Iterator<V> values,
IHandler<? super V,K> keyFunction)
可遍历的元素对象的某个元素,转换为列表
|
static List<String> |
toStringList(List<?> pathList)
对象列表转换为 toString 列表
1.
|
static List<String> |
trimCollection(Collection<String> stringList)
对字符串列表每条字符串执行trim()操作。
|
static <E> List<E> |
union(Collection<E> collectionOne,
Collection<E> collectionTwo)
集合的并集
|
public static final List EMPTY_LIST
public static boolean isEmpty(Collection collection)
collection - 集合true 是public static boolean isNotEmpty(Collection collection)
collection - 集合true 是public static List<String> arrayToList(String[] array)
array - string arraypublic static String[] listToArray(List<String> stringList)
stringList - string listpublic static List<String> trimCollection(Collection<String> stringList)
stringList - 原始的列表public static <T,R> Collection<R> buildCollection(Collection<T> targets, IHandler<T,R> handler)
T - 入参R - 出参targets - 原始信息handler - 处理接口public static <T,R> List<R> buildCollection(T[] targets, IHandler<T,R> handler)
T - 入参R - 出参targets - 原始信息handler - 处理接口public static <T> void addArray(Collection<T> collection, T[] array)
T - 泛型collection - 集合array - 数组public static <K,V> List<K> toList(Iterable<V> values, IHandler<? super V,K> keyFunction)
K - k 泛型V - v 泛型values - 遍历对象keyFunction - 转换方式public static <K,V> List<K> toList(Iterator<V> values, IHandler<? super V,K> keyFunction)
K - k 泛型V - v 泛型values - 遍历对象keyFunction - 转换方式public static <E> List<E> fillList(List<E> values, IFiller<E> filler)
E - e 泛型values - 遍历对象filler - 对象填充器public static List<String> splitByAnyBlank(String string)
string - 字符串public static <T> List<T> filterList(Collection<T> list, IFilter<T> filter)
T - 泛型list - 原始列表filter - 过滤器public static <T> List<T> conditionList(Collection<T> list, ICondition<T> condition)
T - 泛型list - 原始列表condition - 条件过滤器public static List<String> toStringList(List<?> pathList)
pathList - 原始对象public static <T> Optional<T> firstNotNullElem(Collection<T> list)
T - 泛型list - 列表public static String join(Collection<?> stringCollection, String connector)
stringCollection - 字符串集合connector - 连接符号public static String join(Collection<?> stringCollection)
stringCollection - 字符串集合public static <E> void foreach(Collection<E> collection, IHandler<E,Void> handler)
E - 泛型元素collection - 集合handler - 处理器public static <E> void foreachPrint(Collection<E> collection)
E - 泛型元素collection - 集合public static <E> List<E> fill(int size, E elem)
E - 泛型size - 大小elem - 单个元素public static List<Integer> fill(int size, int initValue)
size - 大小initValue - 初始值public static <E> E getFirst(Collection<E> collection)
E - 泛型collection - 列表public static <T> List<T> distinct(Collection<T> collection)
T - 集合元素类型collection - 集合ArrayListpublic static <T extends Comparable> List<T> distinctAndSort(Collection<T> collection)
T - 泛型collection - 原始集合public static <T extends Comparable> List<T> getRepeatList(Collection<T> collection)
T - 泛型collection - 集合public static <T extends Comparable> List<T> sort(List<T> collection)
T - 集合元素类型collection - 集合ArrayListpublic static int getStartIndex(int startIndex,
Collection<?> collection)
startIndex - 开始下标collection - 集合信息public static int getEndIndex(int endIndex,
Collection<?> collection)
endIndex - 结束下标collection - 集合信息public static <E> List<E> union(Collection<E> collectionOne, Collection<E> collectionTwo)
E - 泛型collectionOne - 集合1collectionTwo - 集合2public static <E> List<E> difference(Collection<E> collectionOne, Collection<E> collectionTwo)
E - 泛型collectionOne - 集合1collectionTwo - 集合2public static <E> List<E> interSection(Collection<E> collectionOne, Collection<E> collectionTwo)
E - 泛型collectionOne - 集合1collectionTwo - 集合2public static boolean containAny(Collection<String> firstList, Collection<String> secondList)
firstList - 第一个列表secondList - 第二个列表public static String getLast(List<String> resultList)
resultList - 结果列表public static void setLast(List<String> resultList, String line)
resultList - 结果列表line - 最后一行内容public static <T> List<T> getTopK(Collection<T> collection, int size)
T - 泛型collection - 集合size - 大小public static List<String> replaceAll(Collection<String> collection, String regex, String target)
collection - 集合regex - 正则target - 目标public static <E> List<E> subList(List<E> list, int offset, int limit)
E - 泛型list - 集合1offset - 偏移量limit - 大小public static <E> E random(List<E> list)
E - 元素list - 列表public static <T> List<T> list()
T - 泛型public static <T> List<T> list(T t)
T - 泛型t - 实体public static <T> List<T> list(T... ts)
T - 泛型ts - 数组public static <T> List<T> copy(List<T> list)
T - 泛型list - 列表public static <T> T head(List<T> list)
T - 泛型list - 列表public static <T> T tail(List<T> list)
T - 泛型list - 列表public static <T> List<T> append(List<T> list, T t)
T - 泛型list - 列表t - 元素public static <T> List<T> reverse(List<T> list, T t)
T - 泛型list - 列表t - 元素public static <T> void addAll(Collection<T> collection, Collection<T> addCollection)
T - 泛型collection - 集合1addCollection - 集合2public static <T> T random(Collection<T> collection)
T - 泛型collection - 集合public static <T> List<T> pageList(List<T> list, int pageNum, int pageSize)
T - 泛型list - 列表pageNum - 从1开始pageSize - 每一页大小public static <T> List<T> pageList(Collection<T> collection, int pageNum, int pageSize)
T - 泛型collection - 列表pageNum - 从1开始pageSize - 每一页大小public static boolean contains(Collection<?> collection, Object value)
collection - 集合value - 值Copyright © 2024. All rights reserved.