Original URL: Spring tool class -- the use of CollectionUtils_IT sharp knife unsheathed blog-CSDN blog
Introduction
This article introduces the use of Spring's CollectionUtils.
The role of the CollectionUtils tool class: to operate Collection, such as: List, Set.
judgment
method | effect |
static boolean isEmpty (Collection<?> collection) | Check if the collection is empty. |
static boolean isEmpty(Map<?,?> map) | Determine whether the Map is empty |
static boolean containsInstance ( Collection<?> collection, Object element ) |
Determine whether a collection contains an object |
static boolean contains ( Iterator<?> iterator, Object element ) |
Use an iterator to determine whether an object is in the collection. |
static boolean containsAny ( Collection<?> source, Collection<?> candidates ) |
Determine whether a collection contains any of some objects. |
static boolean hasUniqueObject (Collection<?> collection) | Determine whether each element in the collection is unique. That is, there are no duplicate elements in the collection. |
add to collection
method | effect |
static <E> void mergeArrayIntoCollection ( Object array, Collection<E> collection ) |
Add all elements in the array to the set. |
static <K,V> void mergePropertiesIntoMap ( Properties props, Map<K,V> map ) |
Add the key-value pairs in Properties to Map |
find in collection
method | effect |
static <T> T lastElement (List<T> list) | Returns the last element in the List. |
static <T> T lastElement (Set<T> set) | Returns the last element in the Set. |
static <E> E findFirstMatch ( Collection<?> source, Collection<E> candidates ) |
Returns the first element of candidates present in source. |
static <T> T findValueOfType ( Collection<?> collection, Class<T> type ) |
Returns the elements of the specified type in the collection. |
static Object findValueOfType ( Collection<?> collection, Class<?>[] types ) |
Returns the elements of the specified type in the collection. If the first type is not found, the second type is looked for, and so on. |
static Class<?> findCommonElementType (Collection<?> collection) | Returns the type of the elements in the collection |