public class CollectionUtils extends Object
| 构造器和说明 |
|---|
CollectionUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Collection<?> |
adaptObjectToCollection(Object obj)
Adapt a
Object object to Collection. |
static <T,C extends Collection<T>> |
addAll(C collection,
Collection<T> elements) |
static <T,C extends Collection<T>> |
addAll(C collection,
T... elements)
Add all elements to the collection.
|
static <K,V> V |
computeIfAbsent(Map<K,V> map,
K key,
Function<? super K,? extends V> mappingFunction)
A temporary workaround for Java 8 specific performance issue JDK-8161372 .
|
static boolean |
containsAny(Collection<?> coll1,
Collection<?> coll2)
Check whether coll1 contains any element of coll2.
|
static <T,C extends Collection<T>> |
defaultIfEmpty(C collection,
C defaultCollection)
Get collection if not null, otherwise return default collection.
|
static <T> T |
get(Collection<T> collection,
int index)
Get value specified index from
Collection. |
static <T> T |
get(Iterable<T> iterable,
int index)
Get value specified index from
Iterable. |
static <T> T |
get(Iterator<T> iterable,
int index)
Get value specified index from
Iterable. |
static <T> T |
getFirstNotNull(Iterable<T> iterable)
Get first not null element from the target.
|
static <T> T |
getFirstNotNull(Iterator<T> iterator)
Get first not null element from the target.
|
static boolean |
isEmpty(Collection<?> collection)
Whether the collection is empty.
|
static boolean |
isEmpty(Iterable<?> iterable)
Whether the iterable is empty.
|
static boolean |
isEmpty(Iterator<?> iterator)
Whether the iterator is empty.
|
static boolean |
isEmpty(Map<?,?> map)
Whether the map is empty.
|
static boolean |
isNotEmpty(Collection<?> collection)
Whether the collection is not empty.
|
static boolean |
isNotEmpty(Iterable<?> iterable)
Whether the iterable is not empty.
|
static boolean |
isNotEmpty(Iterator<?> iterator)
Whether the iterator is not empty.
|
static boolean |
isNotEmpty(Map<?,?> map)
Whether the map is not empty.
|
static <T,C extends Collection<T>> |
newCollection(Supplier<C> collectionFactory,
T... elements)
Create a collection from given elements.
|
static <K,V> ConcurrentMap<K,V> |
newWeakConcurrentMap()
Create a thread-safe weak reference collection.
|
static boolean |
notContainsAny(Collection<?> coll1,
Collection<?> coll2)
Check whether coll1 not contains any element of coll2.
|
static <K,V> Map<V,K> |
reverse(Map<K,V> map)
Reverse given map.
|
static <T> List<Collection<T>> |
split(Collection<T> list,
int size)
Split the given list into sub lists.
|
static <T,C extends Collection<T>> |
split(Collection<T> list,
int size,
Function<List<T>,C> mapper)
Split the given list into sub lists.
|
public static <T> List<Collection<T>> split(Collection<T> list, int size)
Split the given list into sub lists.
T - element typelist - listsize - size of sub listpublic static <T,C extends Collection<T>> List<C> split(Collection<T> list, int size, Function<List<T>,C> mapper)
Split the given list into sub lists.
T - element typeC - collection typelist - listsize - size of sub listmapper - mapper to convert list to sub listpublic static <T> T getFirstNotNull(Iterator<T> iterator)
Get first not null element from the target.
T - element typeiterator - iteratorpublic static <T> T getFirstNotNull(Iterable<T> iterable)
Get first not null element from the target.
T - element typeiterable - iterablepublic static <K,V> Map<V,K> reverse(Map<K,V> map)
Reverse given map.
map - map to reversepublic static <T,C extends Collection<T>> C defaultIfEmpty(C collection, C defaultCollection)
Get collection if not null, otherwise return default collection.
T - element typeC - collection typecollection - collectiondefaultCollection - default collectionpublic static boolean containsAny(Collection<?> coll1, Collection<?> coll2)
Check whether coll1 contains any element of coll2.
coll1 - coll1coll2 - coll2public static boolean notContainsAny(Collection<?> coll1, Collection<?> coll2)
Check whether coll1 not contains any element of coll2.
coll1 - coll1coll2 - coll2public static <T> T get(Collection<T> collection, int index)
Get value specified index from Collection.
T - element typecollection - collectionindex - index, if index less than 0 or greater than or equal to collection size, return nullpublic static <T> T get(Iterable<T> iterable, int index)
Get value specified index from Iterable.
T - element typeiterable - iterableindex - indexpublic static <T> T get(Iterator<T> iterable, int index)
Get value specified index from Iterable.
T - element typeiterable - iterableindex - indexpublic static <T,C extends Collection<T>> C addAll(C collection, T... elements)
Add all elements to the collection.
T - element typeC - collection typecollection - collectionelements - elementsCollection itself if not null, or empty collection if nullpublic static <T,C extends Collection<T>> C addAll(C collection, Collection<T> elements)
@SafeVarargs public static <T,C extends Collection<T>> C newCollection(Supplier<C> collectionFactory, T... elements)
Create a collection from given elements.
T - element typeC - collection typecollectionFactory - collection factoryelements - elementspublic static boolean isEmpty(Collection<?> collection)
Whether the collection is empty.
collection - collectionpublic static boolean isNotEmpty(Collection<?> collection)
Whether the collection is not empty.
collection - collectionpublic static boolean isEmpty(Map<?,?> map)
Whether the map is empty.
map - mappublic static boolean isNotEmpty(Map<?,?> map)
Whether the map is not empty.
map - collectionpublic static boolean isEmpty(Iterator<?> iterator)
Whether the iterator is empty.
iterator - iteratorpublic static boolean isNotEmpty(Iterator<?> iterator)
Whether the iterator is not empty.
iterator - iteratorpublic static boolean isEmpty(Iterable<?> iterable)
Whether the iterable is empty.
iterable - iterablepublic static boolean isNotEmpty(Iterable<?> iterable)
Whether the iterable is not empty.
iterable - iterablepublic static <K,V> ConcurrentMap<K,V> newWeakConcurrentMap()
ConcurrentMappublic static Collection<?> adaptObjectToCollection(Object obj)
Object object to Collection.obj - objpublic static <K,V> V computeIfAbsent(Map<K,V> map, K key, Function<? super K,? extends V> mappingFunction)
K - key typeV - value typemap - mapkey - keymappingFunction - mapping functionCopyright © 2024. All rights reserved.