public final class CollectionUtils extends Object
org.apache.commons.collections.| 限定符和类型 | 方法和说明 |
|---|---|
static <T> boolean |
contains(Collection<T> coll,
T target)
Whether contain item in collection.
|
static Object |
get(Object object,
int index)
Returns the
index-th value in object, throwing
IndexOutOfBoundsException if there is no such element or
IllegalArgumentException if object is not an
instance of one of the supported types. |
static <T> T |
getOnlyElement(Iterable<T> iterable)
return the first element, if the iterator contains multiple elements, will throw
IllegalArgumentException. |
static <T> T |
getOrDefault(Object obj,
int index,
T defaultValue)
Returns the value to which the specified index , or
defaultValue if this collection contains no value for
the index. |
static boolean |
isEmpty(Collection coll)
Null-safe check if the specified collection is empty.
|
static boolean |
isListEqual(List<String> firstList,
List<String> secondList)
check list is equal.
|
static boolean |
isMapEmpty(Map<?,?> map)
Return
true if the supplied Map is null or empty. |
static boolean |
isNotEmpty(Collection coll)
Null-safe check if the specified collection is not empty.
|
static <T> List<T> |
list(T... elements)
return an arraylist containing all input parameters.
|
static <T> Set<T> |
set(T... elements)
Return a set containing all input parameters.
|
static int |
size(Object object)
Gets the size of the collection/iterator specified.
|
static boolean |
sizeIsEmpty(Object object)
Judge whether object is empty.
|
public static Object get(Object object, int index)
index-th value in object, throwing
IndexOutOfBoundsException if there is no such element or
IllegalArgumentException if object is not an
instance of one of the supported types.
The supported types, and associated semantics are:
Map.Entry in position
index in the map's entrySet iterator,
if there is such an entry.index-th array entry is returned,
if there is such an entry; otherwise an IndexOutOfBoundsException
is thrown.index-th object
returned by the collection's default iterator, if there is such an element.index-th object in the Iterator/Enumeration, if there
is such an element. The Iterator/Enumeration is advanced to
index (or to the end, if index exceeds the
number of entries) as a side effect of this method.object - the object to get a value fromindex - the index to getIndexOutOfBoundsException - if the index is invalidIllegalArgumentException - if the object type is invalidpublic static int size(Object object)
This method can handles objects as follows
object - the object to get the size ofIllegalArgumentException - thrown if object is not recognised or nullpublic static boolean sizeIsEmpty(Object object)
object - objectIllegalArgumentException - if object has no length or sizepublic static <T> boolean contains(Collection<T> coll, T target)
T - General Typecoll - collectiontarget - target valuepublic static boolean isEmpty(Collection coll)
Null returns true.
coll - the collection to check, may be nullpublic static boolean isNotEmpty(Collection coll)
Null returns false.
coll - the collection to check, may be nullpublic static <T> T getOrDefault(Object obj, int index, T defaultValue)
defaultValue if this collection contains no value for
the index.T - General Typeobj - the object to get a value fromindex - the index to getdefaultValue - default valuedefaultValue if this collection contains no value for
the index.public static <T> List<T> list(T... elements)
elements - element arraypublic static <T> Set<T> set(T... elements)
elements - elements element arraypublic static <T> T getOnlyElement(Iterable<T> iterable)
IllegalArgumentException.NoSuchElementException - if the iterator is emptyIllegalArgumentException - if the iterator contains multiple elements. The state of the iterator is
unspecified.public static boolean isListEqual(List<String> firstList, List<String> secondList)
firstList - first list.secondList - second list.public static boolean isMapEmpty(Map<?,?> map)
true if the supplied Map is null or empty. Otherwise, return false.map - the Map to checkCopyright © 2018–2024 Alibaba Group. All rights reserved.