public class CollectionKit extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> T[] |
addAll(T[]... arrays)
将多个数组合并在一起
忽略null的数组 |
static <T> T[] |
append(T[] buffer,
T newElement)
将新元素添加到已有数组中
添加新元素会生成一个新的数组,不影响原数组 |
static <T> List<T> |
clone(List<T> array)
克隆数组
|
static <T> T[] |
clone(T[] array)
克隆数组
|
static <T> boolean |
contains(T[] array,
T value)
数组中是否包含元素
|
static boolean |
isArray(Object obj)
判定给定对象是否为数组类型
|
static boolean |
isEmpty(Collection<?> collection)
集合是否为空
|
static <V> Collection<V> |
isEmpty(Collection<V> collection,
CollectionConsumption<V> accept)
如果集合为空则执行表达式返回结果,如果集合不为空,则直接返回
|
static boolean |
isEmpty(Iterable<?> iterable)
集合是否为空
|
static <T> boolean |
isEmpty(T[] array)
数组是否为空
|
static boolean |
isNotEmpty(Collection<?> collection)
集合是否为非空
|
static <T> boolean |
isNotEmpty(T[] array)
数组是否为非空
|
static <T> String |
join(Iterable<T> collection,
String conjunction)
以 conjunction 为分隔符将集合转换为字符串
|
static <T> String |
join(String conjunction,
Iterable<T> collection,
ConsumerResult<T,String> consumption)
以 conjunction 为分隔符将集合转换为字符串
|
static <T> String |
join(String conjunction,
T... array)
以 conjunction 为分隔符将数组转换为字符串
|
static <E,T> List<T> |
listToList(E[] list,
ConsumerResult<E,T> consumer)
数组取字段封装为另一个集合
|
static <E,T> List<T> |
listToList(Iterable<E> list,
ConsumerResult<E,T> consumer)
集合取字段封装为另一个集合
|
static <T> T[] |
newArray(Class<?> componentType,
int newSize)
新建一个空数组
|
static <T> ArrayList<T> |
newArrayList()
新建一个ArrayList
|
static <T> ArrayList<T> |
newArrayList(T... values)
新建一个ArrayList
|
static <T> HashSet<T> |
newHashSet()
新建一个HashSet
|
static <T> HashSet<T> |
newHashSet(T... ts)
新建一个HashSet
|
static <T> List<T> |
popPart(Deque<T> surplus,
int partSize)
切取部分数据
|
static <T> List<T> |
popPart(Stack<T> stack,
int partSize)
切取部分数据
|
static int[] |
range(int excludedEnd)
生成一个数字列表
自动判定正序反序 |
static int[] |
range(int includedStart,
int excludedEnd)
生成一个数字列表
自动判定正序反序 |
static int[] |
range(int includedStart,
int excludedEnd,
int step)
生成一个数字列表
自动判定正序反序 |
static <T> T[] |
resize(T[] buffer,
int newSize)
生成一个新的重新设置大小的数组
新数组的类型为原数组的类型 |
static <T> T[] |
resize(T[] buffer,
int newSize,
Class<?> componentType)
生成一个新的重新设置大小的数组
|
static <T> List<T> |
sort(Collection<T> collection,
Comparator<T> comparator)
排序集合
|
static List<Map.Entry<Long,Long>> |
sortEntrySetToList(Set<Map.Entry<Long,Long>> set)
将Set排序(根据Entry的值)
|
static <T> List<T> |
sub(Collection<T> list,
int start,
int end)
截取集合的部分
|
static <T> List<T> |
sub(List<T> list,
int start,
int end)
截取数组的部分
|
static String |
toString(Object obj)
数组或集合转String
|
static <T> TreeSet<T> |
toTreeSet(Collection<T> collection,
Comparator<T> comparator)
将集合转换为排序后的TreeSet
|
static Boolean[] |
wrap(boolean... values)
将基本类型数组包装为包装类型
|
static Byte[] |
wrap(byte... values)
将基本类型数组包装为包装类型
|
static Character[] |
wrap(char... values)
将基本类型数组包装为包装类型
|
static Double[] |
wrap(double... values)
将基本类型数组包装为包装类型
|
static Float[] |
wrap(float... values)
将基本类型数组包装为包装类型
|
static Integer[] |
wrap(int... values)
将基本类型数组包装为包装类型
|
static Integer[] |
wrap(List<Integer> values)
集合转数组
|
static Long[] |
wrap(long... values)
将基本类型数组包装为包装类型
|
static Short[] |
wrap(short... values)
将基本类型数组包装为包装类型
|
static <T> List<T> |
wrap(T... values)
数组转集合
|
static Object[] |
wrapList(List<Object> values)
集合转数组
|
static String[] |
wrapStr(List<String> values)
集合转数组
|
static <T,K> Map<T,K> |
zip(Collection<T> keys,
Collection<K> values)
映射键值(参考Python的zip()函数)
例如: keys = [a,b,c,d] values = [1,2,3,4] 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分 |
static Map<String,String> |
zip(String keys,
String values,
String delimiter)
映射键值(参考Python的zip()函数)
例如: keys = a,b,c,d values = 1,2,3,4 delimiter = , 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分 |
static <T,K> Map<T,K> |
zip(T[] keys,
K[] values)
映射键值(参考Python的zip()函数)
例如: keys = [a,b,c,d] values = [1,2,3,4] 则得到的Map是 {a=1, b=2, c=3, d=4} 如果两个数组长度不同,则只对应最短部分 |
public static <E,T> List<T> listToList(E[] list, ConsumerResult<E,T> consumer)
E - 泛型list - 集合对象consumer - 表达式执行者public static <E,T> List<T> listToList(Iterable<E> list, ConsumerResult<E,T> consumer)
E - 泛型list - 集合对象consumer - 表达式执行者public static <T> String join(Iterable<T> collection, String conjunction)
T - 被处理的集合collection - 集合conjunction - 分隔符public static <T> String join(String conjunction, Iterable<T> collection, ConsumerResult<T,String> consumption)
T - 被处理的集合conjunction - 分隔符collection - 集合consumption - 取值表达式public static <T> String join(String conjunction, T... array)
T - 被处理的集合array - 数组conjunction - 分隔符public static List<Map.Entry<Long,Long>> sortEntrySetToList(Set<Map.Entry<Long,Long>> set)
set - 被排序的Setpublic static <T> List<T> popPart(Stack<T> stack, int partSize)
T - 集合元素类型stack - 原数据partSize - 每部分数据的长度public static <T> List<T> popPart(Deque<T> surplus, int partSize)
T - 集合元素类型surplus - 原数据partSize - 每部分数据的长度public static <T> HashSet<T> newHashSet()
@SafeVarargs public static <T> HashSet<T> newHashSet(T... ts)
public static <T> ArrayList<T> newArrayList()
@SafeVarargs public static <T> ArrayList<T> newArrayList(T... values)
public static <T> T[] append(T[] buffer,
T newElement)
buffer - 已有数组newElement - 新元素public static <T> T[] resize(T[] buffer,
int newSize,
Class<?> componentType)
buffer - 原数组newSize - 新的数组大小componentType - 数组元素类型public static <T> T[] newArray(Class<?> componentType, int newSize)
componentType - 元素类型newSize - 大小public static <T> T[] resize(T[] buffer,
int newSize)
buffer - 原数组newSize - 新的数组大小@SafeVarargs public static <T> T[] addAll(T[]... arrays)
arrays - 数组集合public static <T> T[] clone(T[] array)
array - 被克隆的数组public static int[] range(int excludedEnd)
excludedEnd - 结束的数字(不包含)public static int[] range(int includedStart,
int excludedEnd)
includedStart - 开始的数字(包含)excludedEnd - 结束的数字(不包含)public static int[] range(int includedStart,
int excludedEnd,
int step)
includedStart - 开始的数字(包含)excludedEnd - 结束的数字(不包含)step - 步进public static <T> List<T> sub(List<T> list, int start, int end)
list - 被截取的数组start - 开始位置(包含)end - 结束位置(不包含)public static <T> List<T> sub(Collection<T> list, int start, int end)
list - 被截取的数组start - 开始位置(包含)end - 结束位置(不包含)public static <T> boolean isEmpty(T[] array)
array - 数组public static <T> boolean isNotEmpty(T[] array)
array - 数组public static boolean isEmpty(Collection<?> collection)
collection - 集合public static boolean isEmpty(Iterable<?> iterable)
iterable - 集合public static <V> Collection<V> isEmpty(Collection<V> collection, CollectionConsumption<V> accept)
collection - 集合public static boolean isNotEmpty(Collection<?> collection)
collection - 集合public static <T,K> Map<T,K> zip(T[] keys, K[] values)
keys - 键列表values - 值列表public static Map<String,String> zip(String keys, String values, String delimiter)
keys - 键列表values - 值列表public static <T,K> Map<T,K> zip(Collection<T> keys, Collection<K> values)
keys - 键列表values - 值列表public static <T> boolean contains(T[] array,
T value)
array - 数组value - 被检查的元素public static <T> TreeSet<T> toTreeSet(Collection<T> collection, Comparator<T> comparator)
collection - 集合comparator - 比较器public static <T> List<T> sort(Collection<T> collection, Comparator<T> comparator)
collection - 集合comparator - 比较器public static <T> List<T> wrap(T... values)
values - 数组public static Integer[] wrap(int... values)
values - 基本类型数组public static Long[] wrap(long... values)
values - 基本类型数组public static Character[] wrap(char... values)
values - 基本类型数组public static Byte[] wrap(byte... values)
values - 基本类型数组public static Short[] wrap(short... values)
values - 基本类型数组public static Float[] wrap(float... values)
values - 基本类型数组public static Double[] wrap(double... values)
values - 基本类型数组public static Boolean[] wrap(boolean... values)
values - 基本类型数组public static boolean isArray(Object obj)
obj - 对象Copyright © 2019. All rights reserved.