public final class CollectionUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static List |
EMPTY_LIST
空列表
|
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> void |
addArray(Collection<T> collection,
T[] array)
将数组的内容添加到集合
|
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(List<T> list,
ICondition<T> condition)
执行列表过滤
|
static boolean |
containAny(Collection<String> firstList,
Collection<String> secondList)
包含任何一个
|
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(List<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(List<E> list)
获取第一个元素
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 <E> List<E> |
interSection(Collection<E> collectionOne,
Collection<E> collectionTwo)
集合的差交集
|
static boolean |
isEmpty(Collection collection)
是否为空
|
static boolean |
isNotEmpty(Collection collection)
是否不为空
|
static String |
join(Collection<String> stringCollection)
将字符串集合内容按照逗号连接起来
|
static String |
join(Collection<String> stringCollection,
String connector)
将字符串集合内容按照 connector 连接起来
|
static String[] |
listToArray(List<String> stringList)
列表转数组
|
static <E> E |
random(List<E> list)
随机获取一个元素
|
static List<String> |
replaceAll(Collection<String> collection,
String regex,
String target)
针对整个集合做替换处理
|
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 <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(List<T> list, IFilter<T> filter)
T - 泛型list - 原始列表filter - 过滤器public static <T> List<T> conditionList(List<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<String> stringCollection, String connector)
stringCollection - 字符串集合connector - 连接符号public static String join(Collection<String> 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(List<E> list)
E - 泛型list - 列表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 - 列表Copyright © 2020. All rights reserved.