com.xiaoleilu.hutool
类 CollectionUtil

java.lang.Object
  继承者 com.xiaoleilu.hutool.CollectionUtil

public class CollectionUtil
extends Object

集合相关工具类,包括数组

作者:
xiaoleilu

构造方法摘要
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
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> 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 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> 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}
如果两个数组长度不同,则只对应最短部分
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

CollectionUtil

public CollectionUtil()
方法详细信息

join

public static <T> String join(Iterable<T> collection,
                              String conjunction)
以 conjunction 为分隔符将集合转换为字符串

类型参数:
T - 被处理的集合
参数:
collection - 集合
conjunction - 分隔符
返回:
连接后的字符串

join

public static <T> String join(T[] array,
                              String conjunction)
以 conjunction 为分隔符将数组转换为字符串

类型参数:
T - 被处理的集合
参数:
array - 数组
conjunction - 分隔符
返回:
连接后的字符串

sortPageAll

public static <T> List<T> sortPageAll(int pageNo,
                                      int numPerPage,
                                      Comparator<T> comparator,
                                      Collection<T>... colls)
将多个集合排序并显示不同的段落(分页)

参数:
pageNo - 页码
numPerPage - 每页的条目数
comparator - 比较器
colls - 集合数组
返回:
分页后的段落内容

sortPageAll2

public static <T> List<T> sortPageAll2(int pageNo,
                                       int numPerPage,
                                       Comparator<T> comparator,
                                       Collection<T>... colls)
将多个集合排序并显示不同的段落(分页)

参数:
pageNo - 页码
numPerPage - 每页的条目数
comparator - 比较器
colls - 集合数组
返回:
分业后的段落内容

sortEntrySetToList

public static List<Map.Entry<Long,Long>> sortEntrySetToList(Set<Map.Entry<Long,Long>> set)
将Set排序(根据Entry的值)

参数:
set - 被排序的Set
返回:
排序后的Set

popPart

public static <T> List<T> popPart(Stack<T> surplusAlaDatas,
                                  int partSize)
切取部分数据

类型参数:
T - 集合元素类型
参数:
surplusAlaDatas - 原数据
partSize - 每部分数据的长度
返回:
切取出的数据或null

newHashMap

public static <T,K> HashMap<T,K> newHashMap()
新建一个HashMap

返回:
HashMap对象

newHashMap

public static <T,K> HashMap<T,K> newHashMap(int size)
新建一个HashMap

参数:
size - 初始大小,由于默认负载因子0.75,传入的size会实际初始大小为size / 0.75
返回:
HashMap对象

newHashSet

public static <T> HashSet<T> newHashSet()
新建一个HashSet

返回:
HashSet对象

newArrayList

public static <T> ArrayList<T> newArrayList()
新建一个ArrayList

返回:
ArrayList对象

newArrayList

public static <T> ArrayList<T> newArrayList(T... values)
新建一个ArrayList

返回:
ArrayList对象

append

public static <T> T[] append(T[] buffer,
                             T newElement)
将新元素添加到已有数组中
添加新元素会生成一个新的数组,不影响原数组

参数:
buffer - 已有数组
newElement - 新元素
返回:
新数组

resize

public static <T> T[] resize(T[] buffer,
                             int newSize,
                             Class<?> componentType)
生成一个新的重新设置大小的数组

参数:
buffer - 原数组
newSize - 新的数组大小
componentType - 数组元素类型
返回:
调整后的新数组

newArray

public static <T> T[] newArray(Class<?> componentType,
                               int newSize)
新建一个空数组

参数:
componentType - 元素类型
newSize - 大小
返回:
空数组

resize

public static <T> T[] resize(T[] buffer,
                             int newSize)
生成一个新的重新设置大小的数组
新数组的类型为原数组的类型

参数:
buffer - 原数组
newSize - 新的数组大小
返回:
调整后的新数组

addAll

public static <T> T[] addAll(T[]... arrays)
将多个数组合并在一起
忽略null的数组

参数:
arrays - 数组集合
返回:
合并后的数组

clone

public static <T> T[] clone(T[] array)
克隆数组

参数:
array - 被克隆的数组
返回:
新数组

range

public static int[] range(int excludedEnd)
生成一个数字列表
自动判定正序反序

参数:
excludedEnd - 结束的数字(不包含)
返回:
数字列表

range

public static int[] range(int includedStart,
                          int excludedEnd)
生成一个数字列表
自动判定正序反序

参数:
includedStart - 开始的数字(包含)
excludedEnd - 结束的数字(不包含)
返回:
数字列表

range

public static int[] range(int includedStart,
                          int excludedEnd,
                          int step)
生成一个数字列表
自动判定正序反序

参数:
includedStart - 开始的数字(包含)
excludedEnd - 结束的数字(不包含)
step - 步进
返回:
数字列表

sub

public static <T> List<T> sub(List<T> list,
                              int start,
                              int end)
截取数组的部分

参数:
list - 被截取的数组
start - 开始位置(包含)
end - 结束位置(不包含)
返回:
截取后的数组,当开始位置超过最大时,返回null

sub

public static <T> List<T> sub(Collection<T> list,
                              int start,
                              int end)
截取集合的部分

参数:
list - 被截取的数组
start - 开始位置(包含)
end - 结束位置(不包含)
返回:
截取后的数组,当开始位置超过最大时,返回null

isEmpty

public static <T> boolean isEmpty(T[] array)
数组是否为空

参数:
array - 数组
返回:
是否为空

isNotEmpty

public static <T> boolean isNotEmpty(T[] array)
数组是否为非空

参数:
array - 数组
返回:
是否为非空

isEmpty

public static <T> boolean isEmpty(Collection<T> collection)
集合是否为空

参数:
collection - 集合
返回:
是否为空

isNotEmpty

public static <T> boolean isNotEmpty(Collection<T> collection)
集合是否为非空

参数:
collection - 集合
返回:
是否为非空

zip

public 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}
如果两个数组长度不同,则只对应最短部分

参数:
keys - 键列表
values - 值列表
返回:
Map

zip

public 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}
如果两个数组长度不同,则只对应最短部分

参数:
keys - 键列表
values - 值列表
返回:
Map

zip

public 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}
如果两个数组长度不同,则只对应最短部分

参数:
keys - 键列表
values - 值列表
返回:
Map


Copyright © 2014. All rights reserved.