public class CollectionUtil extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
CollectionUtil.Consumer<T>
针对一个参数做相应的操作
|
static interface |
CollectionUtil.KVConsumer<K,V>
针对两个参数做相应的操作,例如Map中的KEY和VALUE
|
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> Collection<T> |
addAll(Collection<T> collection,
Enumeration<T> enumeration)
加入全部
|
static <T> Collection<T> |
addAll(Collection<T> collection,
Iterable<T> iterable)
加入全部
|
static <T> Collection<T> |
addAll(Collection<T> collection,
Iterator<T> iterator)
加入全部
|
static <E> Enumeration<E> |
asEnumeration(Iterator<E> iter)
Iterator转换为Enumeration Adapt the specified
Iterator to the Enumeration interface. |
static <E> Iterator<E> |
asIterator(Enumeration<E> e)
Enumeration转换为Iterator
Adapt the specified Enumeration to the Iterator interface |
static boolean |
containsAny(Collection<?> coll1,
Collection<?> coll2)
其中一个集合在另一个集合中是否至少包含一个元素,既是两个集合是否至少有一个共同的元素
|
static <T> int |
count(Iterable<T> iterable,
Matcher<T> matcher)
集合中匹配规则的数量
|
static <T> Map<T,Integer> |
countMap(Collection<T> collection)
|
static <T> Collection<T> |
disjunction(Collection<T> coll1,
Collection<T> coll2)
两个集合的差集
针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留两个集合中此元素个数差的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[c],此结果中只保留了一个 |
static <T> ArrayList<T> |
distinct(Collection<T> collection)
去重集合
|
static <T> Collection<T> |
filter(Collection<T> collection,
Editor<T> editor)
过滤
过滤会改变原集合的内容 |
static <K,V> Map<K,V> |
filter(Map<K,V> map,
Editor<Map.Entry<K,V>> editor)
过滤
|
static <T> void |
forEach(Enumeration<T> enumeration,
CollectionUtil.Consumer<T> consumer)
循环遍历
Enumeration,使用CollectionUtil.Consumer 接受遍历的每条数据,并针对每条数据做处理 |
static <T> void |
forEach(Iterator<T> iterator,
CollectionUtil.Consumer<T> consumer)
循环遍历
Iterator,使用CollectionUtil.Consumer 接受遍历的每条数据,并针对每条数据做处理 |
static <K,V> void |
forEach(Map<K,V> map,
CollectionUtil.KVConsumer<K,V> kvConsumer)
循环遍历Map,使用
CollectionUtil.KVConsumer 接受遍历的每条数据,并针对每条数据做处理 |
static <T> Collection<T> |
intersection(Collection<T> coll1,
Collection<T> coll2)
两个集合的交集
针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最少的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c],此结果中只保留了两个c |
static <T> Collection<T> |
intersection(Collection<T> coll1,
Collection<T> coll2,
Collection<T>... otherColls)
多个集合的交集
针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最少的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c],此结果中只保留了两个c |
static boolean |
isEmpty(Collection<?> collection)
集合是否为空
|
static boolean |
isEmpty(Enumeration<?> enumeration)
Enumeration是否为空
|
static boolean |
isEmpty(Iterable<?> iterable)
Iterable是否为空
|
static boolean |
isEmpty(Iterator<?> Iterator)
Iterator是否为空
|
static boolean |
isEmpty(Map<?,?> map)
Map是否为空
|
static boolean |
isNotEmpty(Collection<?> collection)
集合是否为非空
|
static boolean |
isNotEmpty(Enumeration<?> enumeration)
Enumeration是否为空
|
static boolean |
isNotEmpty(Iterable<?> iterable)
Iterable是否为空
|
static boolean |
isNotEmpty(Iterator<?> Iterator)
Iterator是否为空
|
static <T> boolean |
isNotEmpty(Map<?,?> map)
Map是否为非空
|
static <T> String |
join(Iterable<T> iterable,
String conjunction)
以 conjunction 为分隔符将集合转换为字符串
|
static <T> String |
join(Iterator<T> iterator,
String conjunction)
以 conjunction 为分隔符将集合转换为字符串
|
static <T> ArrayList<T> |
newArrayList(Collection<T> collection)
新建一个ArrayList
|
static <T> ArrayList<T> |
newArrayList(T... values)
新建一个ArrayList
|
static <T,K> HashMap<T,K> |
newHashMap()
新建一个HashMap
|
static <T,K> HashMap<T,K> |
newHashMap(boolean isSorted)
新建一个HashMap
|
static <T,K> HashMap<T,K> |
newHashMap(int size)
新建一个HashMap
|
static <T> HashSet<T> |
newHashSet(boolean isSorted,
Collection<T> collection)
新建一个HashSet
|
static <T> HashSet<T> |
newHashSet(boolean isSorted,
T... ts)
新建一个HashSet
|
static <T> HashSet<T> |
newHashSet(Collection<T> collection)
新建一个HashSet
|
static <T> HashSet<T> |
newHashSet(T... ts)
新建一个HashSet
|
static <T> List<T> |
popPart(Deque<T> surplusAlaDatas,
int partSize)
切取部分数据
|
static <T> List<T> |
popPart(Stack<T> surplusAlaDatas,
int partSize)
切取部分数据
|
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<List<T>> |
split(Collection<T> collection,
int size)
对集合按照指定长度分段,每一个段为单独的集合,返回这个集合的列表
|
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 <T> Collection<T> |
union(Collection<T> coll1,
Collection<T> coll2)
两个集合的并集
针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最多的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c],此结果中只保留了三个c |
static <T> Collection<T> |
union(Collection<T> coll1,
Collection<T> coll2,
Collection<T>... otherColls)
多个集合的并集
针对一个集合中存在多个相同元素的情况,计算两个集合中此元素的个数,保留最多的个数 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c] 结果:[a, b, c, c, c],此结果中只保留了三个c |
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} 如果两个数组长度不同,则只对应最短部分 |
public static <T> Collection<T> union(Collection<T> coll1, Collection<T> coll2)
coll1 - 集合1coll2 - 集合2ArrayList@SafeVarargs public static <T> Collection<T> union(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
coll1 - 集合1coll2 - 集合2otherColls - 其它集合ArrayListpublic static <T> Collection<T> intersection(Collection<T> coll1, Collection<T> coll2)
coll1 - 集合1coll2 - 集合2ArrayList@SafeVarargs public static <T> Collection<T> intersection(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls)
coll1 - 集合1coll2 - 集合2otherColls - 其它集合ArrayListpublic static <T> Collection<T> disjunction(Collection<T> coll1, Collection<T> coll2)
coll1 - 集合1coll2 - 集合2ArrayListpublic static boolean containsAny(Collection<?> coll1, Collection<?> coll2)
coll1 - 集合1coll2 - 集合2intersection(java.util.Collection<T>, java.util.Collection<T>)public static <T> Map<T,Integer> countMap(Collection<T> collection)
collection - 集合Mappublic static <T> String join(Iterable<T> iterable, String conjunction)
T - 被处理的集合iterable - Iterableconjunction - 分隔符public static <T> String join(Iterator<T> iterator, String conjunction)
T - 被处理的集合iterator - 集合conjunction - 分隔符@SafeVarargs public static <T> List<T> sortPageAll(int pageNo, int numPerPage, Comparator<T> comparator, Collection<T>... colls)
pageNo - 页码,从1开始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> List<T> popPart(Deque<T> surplusAlaDatas, int partSize)
T - 集合元素类型surplusAlaDatas - 原数据partSize - 每部分数据的长度public static <T,K> HashMap<T,K> newHashMap()
public static <T,K> HashMap<T,K> newHashMap(boolean isSorted)
isSorted - Map的Key是否有序,有序返回 LinkedHashMap,否则返回 HashMappublic static <T,K> HashMap<T,K> newHashMap(int size)
size - 初始大小,由于默认负载因子0.75,传入的size会实际初始大小为size / 0.75@SafeVarargs public static <T> HashSet<T> newHashSet(T... ts)
ts - 元素数组@SafeVarargs public static <T> HashSet<T> newHashSet(boolean isSorted, T... ts)
isSorted - 是否有序,有序返回 LinkedHashSet,否则返回 HashSetts - 元素数组public static <T> HashSet<T> newHashSet(Collection<T> collection)
public static <T> HashSet<T> newHashSet(boolean isSorted, Collection<T> collection)
@SafeVarargs public static <T> ArrayList<T> newArrayList(T... values)
values - 数组public static <T> ArrayList<T> newArrayList(Collection<T> collection)
collection - 集合public static <T> ArrayList<T> distinct(Collection<T> collection)
collection - 集合ArrayListpublic 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> List<List<T>> split(Collection<T> collection, int size)
collection - 集合size - 每个段的长度public static <T> Collection<T> filter(Collection<T> collection, Editor<T> editor)
collection - 集合editor - 编辑器接口public static <K,V> Map<K,V> filter(Map<K,V> map, Editor<Map.Entry<K,V>> editor)
map - Mapeditor - 编辑器接口public static <T> int count(Iterable<T> iterable, Matcher<T> matcher)
iterable - Iterablematcher - 匹配器,为空则全部匹配public static boolean isEmpty(Collection<?> collection)
collection - 集合public static boolean isEmpty(Map<?,?> map)
map - 集合public static boolean isEmpty(Iterable<?> iterable)
iterable - Iterable对象public static boolean isEmpty(Iterator<?> Iterator)
Iterator - Iterator对象public static boolean isEmpty(Enumeration<?> enumeration)
enumeration - Enumerationpublic static boolean isNotEmpty(Collection<?> collection)
collection - 集合public static <T> boolean isNotEmpty(Map<?,?> map)
map - 集合public static boolean isNotEmpty(Iterable<?> iterable)
iterable - Iterable对象public static boolean isNotEmpty(Iterator<?> Iterator)
Iterator - Iterator对象public static boolean isNotEmpty(Enumeration<?> enumeration)
enumeration - Enumerationpublic 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,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 <E> Enumeration<E> asEnumeration(Iterator<E> iter)
Iterator to the Enumeration interface.iter - Iteratorpublic static <E> Iterator<E> asIterator(Enumeration<E> e)
Enumeration to the Iterator interfacee - Enumerationpublic static <T> Collection<T> addAll(Collection<T> collection, Iterator<T> iterator)
collection - 集合 Collectioniterator - Iteratorpublic static <T> Collection<T> addAll(Collection<T> collection, Iterable<T> iterable)
collection - 集合 Collectioniterable - Iterablepublic static <T> Collection<T> addAll(Collection<T> collection, Enumeration<T> enumeration)
collection - 集合 Collectionenumeration - Enumerationpublic static <T> void forEach(Iterator<T> iterator, CollectionUtil.Consumer<T> consumer)
Iterator,使用CollectionUtil.Consumer 接受遍历的每条数据,并针对每条数据做处理iterator - Iteratorconsumer - CollectionUtil.Consumer 遍历的每条数据处理器public static <T> void forEach(Enumeration<T> enumeration, CollectionUtil.Consumer<T> consumer)
Enumeration,使用CollectionUtil.Consumer 接受遍历的每条数据,并针对每条数据做处理enumeration - Enumerationconsumer - CollectionUtil.Consumer 遍历的每条数据处理器public static <K,V> void forEach(Map<K,V> map, CollectionUtil.KVConsumer<K,V> kvConsumer)
CollectionUtil.KVConsumer 接受遍历的每条数据,并针对每条数据做处理map - MapkvConsumer - CollectionUtil.KVConsumer 遍历的每条数据处理器Copyright © 2017. All rights reserved.