public class CollectionKits extends Object
copy from vipshop VJTools(com.vip.vjtools.vjkit.collection.CollectionUtil) and made some changes.
| 构造器和说明 |
|---|
CollectionKits() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends Comparable<?>> |
bottomN(Iterable<T> coll,
int n)
返回Iterable中最小的N个对象, back by guava.
|
static <T> List<T> |
bottomN(Iterable<T> coll,
int n,
Comparator<? super T> comp)
返回Iterable中最小的N个对象, back by guava.
|
static boolean |
elementsEqual(Iterable<?> iterable1,
Iterable<?> iterable2)
两个集合中的所有元素按顺序相等.
|
static <T> T |
getFirst(Collection<T> collection)
取得Collection的第一个元素,如果collection为空返回null.
|
static <T> T |
getLast(Collection<T> collection)
获取Collection的最后一个元素,如果collection为空返回null.
|
static boolean |
isEmpty(Collection<?> collection)
判断是否为空.
|
static boolean |
isNotEmpty(Collection<?> collection)
判断是否不为空.
|
static <T extends Object & Comparable<? super T>> |
minAndMax(Collection<? extends T> coll)
同时返回无序集合中的最小值和最大值,使用元素默认排序
在返回的Pair中,第一个为最小值,第二个为最大值
|
static <T> Pair<T,T> |
minAndMax(Collection<? extends T> coll,
Comparator<? super T> comp)
返回无序集合中的最小值和最大值
在返回的Pair中,第一个为最小值,第二个为最大值
|
static <T extends Comparable<?>> |
topN(Iterable<T> coll,
int n)
返回Iterable中最大的N个对象, back by guava.
|
static <T> List<T> |
topN(Iterable<T> coll,
int n,
Comparator<? super T> comp)
返回Iterable中最大的N个对象, back by guava.
|
public static boolean isEmpty(Collection<?> collection)
public static boolean isNotEmpty(Collection<?> collection)
public static <T> T getFirst(Collection<T> collection)
public static <T> T getLast(Collection<T> collection)
public static boolean elementsEqual(Iterable<?> iterable1, Iterable<?> iterable2)
public static <T extends Object & Comparable<? super T>> Pair<T,T> minAndMax(Collection<? extends T> coll)
在返回的Pair中,第一个为最小值,第二个为最大值
public static <T> Pair<T,T> minAndMax(Collection<? extends T> coll, Comparator<? super T> comp)
在返回的Pair中,第一个为最小值,第二个为最大值
public static <T extends Comparable<?>> List<T> topN(Iterable<T> coll, int n)
public static <T> List<T> topN(Iterable<T> coll, int n, Comparator<? super T> comp)
public static <T extends Comparable<?>> List<T> bottomN(Iterable<T> coll, int n)
public static <T> List<T> bottomN(Iterable<T> coll, int n, Comparator<? super T> comp)
Copyright © 2019. All rights reserved.