class ArrayUtils
extends java.lang.Object
Operations on arrays, primitive arrays (like int[]
) and primitive wrapper arrays (like Integer[]
).
This class tries to handle null
input gracefully. An exception will not be thrown for a null
array
input. However, an Object array that contains a null
element may throw an exception. Each method documents
its behaviour.
Package private, might move to an internal package if this needs to be public.
#ThreadSafe#
Modifier and Type | Field and Description |
---|---|
(package private) static int |
INDEX_NOT_FOUND
The index value when an element is not found in a list or array:
-1 . |
Constructor and Description |
---|
ArrayUtils() |
Modifier and Type | Method and Description |
---|---|
(package private) static boolean |
contains(java.lang.Object[] array,
java.lang.Object objectToFind)
Checks if the object is in the given array.
|
(package private) static int |
indexOf(java.lang.Object[] array,
java.lang.Object objectToFind,
int startIndex)
Finds the index of the given object in the array starting at the given index.
|
(package private) static <T> int |
indexOf(T[] array,
java.lang.Object objectToFind)
Finds the index of the given object in the array.
|
static final int INDEX_NOT_FOUND
-1
. This value is returned by methods in
this class and can also be used in comparisons with values returned by various method from
List
.static boolean contains(java.lang.Object[] array, java.lang.Object objectToFind)
Checks if the object is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughobjectToFind
- the object to findtrue
if the array contains the objectstatic <T> int indexOf(T[] array, java.lang.Object objectToFind)
Finds the index of the given object in the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to search through for the object, may be null
objectToFind
- the object to find, may be null
INDEX_NOT_FOUND
(-1
) if not found or
null
array inputstatic int indexOf(java.lang.Object[] array, java.lang.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 a null
input array.
A negative startIndex is treated as zero. A startIndex larger than the array length will return
INDEX_NOT_FOUND
(-1
).
array
- the array to search through for the object, may be null
objectToFind
- the object to find, may be null
startIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if
not found or null
array input