public final class CollectionUtils extends Object
org.apache.commons.collections.| 构造器和说明 |
|---|
CollectionUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
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 |
getOrDefault(Collection<T> coll,
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 |
isNotEmpty(Collection coll)
Null-safe check if the specified collection is not empty.
|
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 - Genreal 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(Collection<T> coll, int index, T defaultValue)
defaultValue if this collection contains no value for
the index.T - General Typecoll - the collection to get a value fromindex - the index to getdefaultValue - default valuedefaultValue if this collection contains no value for
the index.Copyright © 2018–2020 Alibaba Group. All rights reserved.