类 CollectionUtils
java.lang.Object
com.alibaba.nacos.common.utils.CollectionUtils
Copy from
org.apache.commons.collections.- 作者:
- liaochuntao
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static <T> booleancontains(Collection<T> coll, T target)Whether contain item in collection.static ObjectReturns theindex-th value inobject, throwingIndexOutOfBoundsExceptionif there is no such element orIllegalArgumentExceptionifobjectis not an instance of one of the supported types.static <T> TgetOrDefault(Collection<T> coll, int index, T defaultValue)Returns the value to which the specified index , ordefaultValueif this collection contains no value for the index.static booleanisEmpty(Collection coll)Null-safe check if the specified collection is empty.static booleanisNotEmpty(Collection coll)Null-safe check if the specified collection is not empty.static intGets the size of the collection/iterator specified.static booleansizeIsEmpty(Object object)Judge whether object is empty.
-
构造器详细资料
-
CollectionUtils
public CollectionUtils()
-
-
方法详细资料
-
get
Returns theindex-th value inobject, throwingIndexOutOfBoundsExceptionif there is no such element orIllegalArgumentExceptionifobjectis not an instance of one of the supported types.The supported types, and associated semantics are:
- Map -- the value returned is the
Map.Entryin positionindexin the map'sentrySetiterator, if there is such an entry. - List -- this method is equivalent to the list's get method.
- Array -- the
index-th array entry is returned, if there is such an entry; otherwise anIndexOutOfBoundsExceptionis thrown. - Collection -- the value returned is the
index-th object returned by the collection's default iterator, if there is such an element. - Iterator or Enumeration -- the value returned is the
index-th object in the Iterator/Enumeration, if there is such an element. The Iterator/Enumeration is advanced toindex(or to the end, ifindexexceeds the number of entries) as a side effect of this method.
- 参数:
object- the object to get a value fromindex- the index to get- 返回:
- the object at the specified index
- 抛出:
IndexOutOfBoundsException- if the index is invalidIllegalArgumentException- if the object type is invalid
- Map -- the value returned is the
-
size
Gets the size of the collection/iterator specified.This method can handles objects as follows
- Collection - the collection size
- Map - the map size
- Array - the array size
- Iterator - the number of elements remaining in the iterator
- Enumeration - the number of elements remaining in the enumeration
- 参数:
object- the object to get the size of- 返回:
- the size of the specified collection
- 抛出:
IllegalArgumentException- thrown if object is not recognised or null- 从以下版本开始:
- Commons Collections 3.1
-
sizeIsEmpty
Judge whether object is empty.- 参数:
object- object- 返回:
- true if object is empty, otherwise false
- 抛出:
IllegalArgumentException- if object has no length or size
-
contains
Whether contain item in collection.- 类型参数:
T- General Type- 参数:
coll- collectiontarget- target value- 返回:
- true if contain, otherwise false
-
isEmpty
Null-safe check if the specified collection is empty.Null returns true.
- 参数:
coll- the collection to check, may be null- 返回:
- true if empty or null
- 从以下版本开始:
- Commons Collections 3.2
-
isNotEmpty
Null-safe check if the specified collection is not empty.Null returns false.
- 参数:
coll- the collection to check, may be null- 返回:
- true if non-null and non-empty
- 从以下版本开始:
- Commons Collections 3.2
-
getOrDefault
Returns the value to which the specified index , ordefaultValueif this collection contains no value for the index.- 类型参数:
T- General Type- 参数:
coll- the collection to get a value fromindex- the index to getdefaultValue- default value- 返回:
- the value to which the specified index , or
defaultValueif this collection contains no value for the index.
-