public final class CollectionUtil extends Object
| Constructor and Description |
|---|
CollectionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
allUnique(Collection<?> collection) |
static <T> boolean |
hasIntersection(List<T> first,
Set<T> second) |
static <T> boolean |
hasIntersection(Set<T> first,
Set<T> second) |
static <T> Collection<T> |
intersect(Collection<T> first,
Collection<T> second)
Find the intersection of two collections, the original collections
will not be modified
|
static <T> Collection<T> |
intersectWithModify(Collection<T> first,
Collection<T> second)
Find the intersection of two collections, note that the first collection
will be modified and store the results
|
static <T> boolean |
prefixOf(List<T> prefix,
List<T> all) |
static Set<Integer> |
randomSet(int min,
int max,
int count) |
static <K extends Comparable<? super K>,V> |
sortByKey(Map<K,V> map,
boolean incr) |
static <K,V extends Comparable<? super V>> |
sortByValue(Map<K,V> map,
boolean incr) |
static <T> Set<T> |
subSet(Set<T> original,
int from,
int to)
Get sub-set of a set.
|
static <T> List<T> |
toList(Object object) |
static <T> Set<T> |
toSet(Object object) |
static <T> Set<T> |
union(Collection<T> first,
Collection<T> second) |
public static boolean allUnique(Collection<?> collection)
public static <T> Set<T> subSet(Set<T> original, int from, int to)
T - element type of setoriginal - original setfrom - index of start positionto - index of end position(exclude), but -1 means the last elementpublic static <T> Set<T> union(Collection<T> first, Collection<T> second)
public static <T> Collection<T> intersect(Collection<T> first, Collection<T> second)
T - element type of collectionfirst - the first collectionsecond - the second collectionpublic static <T> Collection<T> intersectWithModify(Collection<T> first, Collection<T> second)
T - element type of collectionfirst - the first collection, it will be modifiedsecond - the second collectionpublic static <K extends Comparable<? super K>,V> Map<K,V> sortByKey(Map<K,V> map, boolean incr)
public static <K,V extends Comparable<? super V>> Map<K,V> sortByValue(Map<K,V> map, boolean incr)
Copyright © 2021. All rights reserved.