public class CollectionUtil extends Object
| 构造器和说明 |
|---|
CollectionUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> T[] |
addAll(T[]... arrays)
将多个数组合并在一起
忽略null的数组 |
static <T> T[] |
append(T[] buffer,
T newElement)
将新元素添加到已有数组中
添加新元素会生成一个新的数组,不影响原数组 |
static <T> T[] |
clone(T[] array)
克隆数组
|
static <T> boolean |
contains(T[] array,
T value)
数组中是否包含元素
|
static <T> boolean |
isEmpty(Collection<T> collection)
集合是否为空
|
static <T> boolean |
isEmpty(T[] array)
数组是否为空
|
static <T> boolean |
isNotEmpty(Collection<T> collection)
集合是否为非空
|
static <T> boolean |
isNotEmpty(T[] array)
数组是否为非空
|
static <T> String |
join(Iterable<T> collection,
String conjunction)
以 conjunction 为分隔符将集合转换为字符串
|
static <T> String |
join(T[] array,
String conjunction)
以 conjunction 为分隔符将数组转换为字符串
|
static <T> T[] |
newArray(Class<?> componentType,
int newSize)
新建一个空数组
|
static <T> ArrayList<T> |
newArrayList()
新建一个ArrayList
|
static <T> ArrayList<T> |
newArrayList(T... values)
新建一个ArrayList
|
static <T,K> HashMap<T,K> |
newHashMap()
新建一个HashMap
|
static <T,K> HashMap<T,K> |
newHashMap(int size)
新建一个HashMap
|
static <T> HashSet<T> |
newHashSet()
新建一个HashSet
|
static <T> HashSet<T> |
newHashSet(T... ts)
新建一个HashSet
|
static <T> List<T> |
popPart(Stack<T> surplusAlaDatas,
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> |
sortPageAll(int pageNo,
int numPerPage,
Comparator<T> comparator,
Collection<T>... colls)
将多个集合排序并显示不同的段落(分页)
|
static <T> List<T> |
sortPageAll2(int pageNo,
int numPerPage,
Comparator<T> comparator,
Collection<T>... colls)
将多个集合排序并显示不同的段落(分页)
|
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 <T,K> HashMap<T,K> |
toMap(Collection<Map.Entry<T,K>> entryCollection)
将Entry集合转换为HashMap
|
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 Long[] |
wrap(long... values)
将基本类型数组包装为包装类型
|
static Short[] |
wrap(short... 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 <T> String join(Iterable<T> collection, String conjunction)
T - 被处理的集合collection - 集合conjunction - 分隔符public static <T> String join(T[] array, String conjunction)
T - 被处理的集合array - 数组conjunction - 分隔符@SafeVarargs public static <T> List<T> sortPageAll(int pageNo, int numPerPage, Comparator<T> comparator, Collection<T>... colls)
pageNo - 页码numPerPage - 每页的条目数comparator - 比较器colls - 集合数组@SafeVarargs public static <T> List<T> sortPageAll2(int pageNo, int numPerPage, Comparator<T> comparator, Collection<T>... colls)
pageNo - 页码numPerPage - 每页的条目数comparator - 比较器colls - 集合数组public static List<Map.Entry<Long,Long>> sortEntrySetToList(Set<Map.Entry<Long,Long>> set)
set - 被排序的Setpublic static <T> List<T> popPart(Stack<T> surplusAlaDatas, int partSize)
T - 集合元素类型surplusAlaDatas - 原数据partSize - 每部分数据的长度public static <T,K> HashMap<T,K> newHashMap()
public static <T,K> HashMap<T,K> newHashMap(int size)
size - 初始大小,由于默认负载因子0.75,传入的size会实际初始大小为size / 0.75public 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 <T> boolean isEmpty(Collection<T> collection)
collection - 集合public static <T> boolean isNotEmpty(Collection<T> 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,K> HashMap<T,K> toMap(Collection<Map.Entry<T,K>> entryCollection)
entryCollection - entry集合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 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 - 基本类型数组Copyright © 2015. All rights reserved.