public class CollectionUtils extends Object
Utility methods for working with Collection types
| Constructor and Description | 
|---|
CollectionUtils()  | 
| Modifier and Type | Method and Description | 
|---|---|
static <T> Optional<Iterable<T>> | 
convertCollection(Class<? extends Iterable<T>> iterableType,
                 Collection<T> collection)
Attempts to convert a collection to the given iterabable type 
 | 
static <T> Iterable<T> | 
enumerationToIterable(Enumeration<T> enumeration)
Convert an  
Enumeration to a Iterable. | 
static <T> Set<T> | 
enumerationToSet(Enumeration<T> enumeration)
Convert an  
Enumeration to a Set. | 
static boolean | 
isEmpty(Collection collection)
Null safe empty check. 
 | 
static boolean | 
isEmpty(Map map)
Null safe empty check. 
 | 
static boolean | 
isIterableOrMap(Class<?> type)
Is the given type an iterable or map type. 
 | 
static boolean | 
isNotEmpty(Collection collection)
Null safe not empty check. 
 | 
static boolean | 
isNotEmpty(Map map)
Null safe not empty check. 
 | 
static <T> List<T> | 
iterableToList(Iterable<T> iterable)
 | 
static <T> Set<T> | 
iterableToSet(Iterable<T> iterable)
 | 
static <T> Set<T> | 
iteratorToSet(Iterator<T> iterator)
 | 
static <T> T | 
last(Collection<T> collection)
Returns the last element of a collection. 
 | 
static Map | 
mapOf(Object... values)
Create a  
LinkedHashMap from an array of values. | 
static <T> Set<T> | 
setOf(T... objects)
Creates a set of the given objects. 
 | 
static String | 
toString(Iterable<?> iterable)
Produce a string representation of the given iterable. 
 | 
static String | 
toString(String delimiter,
        Iterable<?> iterable)
Produce a string representation of the given iterable. 
 | 
static <T> List<T> | 
unmodifiableList(List<T> list)
Null safe version of  
Collections.unmodifiableList(List). | 
public static boolean isIterableOrMap(Class<?> type)
type - The typepublic static boolean isEmpty(@Nullable Map map)
map - The mappublic static boolean isNotEmpty(@Nullable Map map)
map - The ,appublic static boolean isEmpty(@Nullable Collection collection)
collection - The collectionpublic static boolean isNotEmpty(@Nullable Collection collection)
collection - The collectionpublic static <T> Optional<Iterable<T>> convertCollection(Class<? extends Iterable<T>> iterableType, Collection<T> collection)
Attempts to convert a collection to the given iterabable type
.T - The collection generic typeiterableType - The iterable typecollection - The collectionOptional of the converted typepublic static Map mapOf(Object... values)
LinkedHashMap from an array of values.values - The valuespublic static <T> Set<T> iteratorToSet(Iterator<T> iterator)
T - The typeiterator - The iteratorpublic static <T> Set<T> enumerationToSet(Enumeration<T> enumeration)
Enumeration to a Set.T - The typeenumeration - The iterator@NonNull public static <T> Iterable<T> enumerationToIterable(@Nullable Enumeration<T> enumeration)
Enumeration to a Iterable.T - The typeenumeration - The iteratorpublic static <T> Set<T> setOf(T... objects)
T - The typeobjects - The objectspublic static String toString(Iterable<?> iterable)
iterable - The iterablepublic static String toString(String delimiter, Iterable<?> iterable)
delimiter - The delimiteriterable - The iterablepublic static <T> List<T> iterableToList(Iterable<T> iterable)
T - The generic typeiterable - The iterablepublic static <T> Set<T> iterableToSet(Iterable<T> iterable)
T - The generic typeiterable - The iterable@NonNull public static <T> List<T> unmodifiableList(@Nullable List<T> list)
Collections.unmodifiableList(List).T - The generic typelist - The list@Nullable public static <T> T last(@NonNull Collection<T> collection)
T - The generic typecollection - The collection