Class ArrayUtils
- java.lang.Object
-
- org.apache.commons.collections4.ArrayUtils
-
class ArrayUtils extends Object
Operations on arrays, primitive arrays (like
int[]) and primitive wrapper arrays (likeInteger[]).This class tries to handle
nullinput gracefully. An exception will not be thrown for anullarray input. However, an Object array that contains anullelement may throw an exception. Each method documents its behaviour.Package private, might move to an internal package if this needs to be public.
#ThreadSafe#
- Since:
- 4.2 (Copied from Apache Commons Lang.)
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intINDEX_NOT_FOUNDThe index value when an element is not found in a list or array:-1.
-
Constructor Summary
Constructors Constructor Description ArrayUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static booleancontains(Object[] array, Object objectToFind)Checks if the object is in the given array.(package private) static intindexOf(Object[] array, Object objectToFind, int startIndex)Finds the index of the given object in the array starting at the given index.(package private) static <T> intindexOf(T[] array, Object objectToFind)Finds the index of the given object in the array.
-
-
-
Field Detail
-
INDEX_NOT_FOUND
static final int INDEX_NOT_FOUND
The index value when an element is not found in a list or array:-1. This value is returned by methods in this class and can also be used in comparisons with values returned by various method fromList.- See Also:
- Constant Field Values
-
-
Method Detail
-
contains
static boolean contains(Object[] array, Object objectToFind)
Checks if the object is in the given array.
The method returns
falseif anullarray is passed in.- Parameters:
array- the array to search throughobjectToFind- the object to find- Returns:
trueif the array contains the object
-
indexOf
static <T> int indexOf(T[] array, Object objectToFind)Finds the index of the given object in the array.
This method returns
INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array- the array to search through for the object, may benullobjectToFind- the object to find, may benull- Returns:
- the index of the object within the array,
INDEX_NOT_FOUND(-1) if not found ornullarray input
-
indexOf
static int indexOf(Object[] array, Object objectToFind, int startIndex)
Finds the index of the given object in the array starting at the given index.
This method returns
INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
INDEX_NOT_FOUND(-1).- Parameters:
array- the array to search through for the object, may benullobjectToFind- the object to find, may benullstartIndex- the index to start searching at- Returns:
- the index of the object within the array starting at the index,
INDEX_NOT_FOUND(-1) if not found ornullarray input
-
-