Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.lang.ArrayUtils
public class ArrayUtils
extends java.lang.Object
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.
Field Summary | |
static boolean[] |
|
static Boolean[] |
|
static byte[] |
|
static Byte[] |
|
static Character[] |
|
static char[] |
|
static Class[] |
|
static double[] |
|
static Double[] |
|
static float[] |
|
static Float[] |
|
static Integer[] |
|
static int[] |
|
static long[] |
|
static Long[] |
|
static Object[] |
|
static short[] |
|
static Short[] |
|
static String[] |
|
Constructor Summary | |
|
Method Summary | |
static Object[] |
|
static boolean[] |
|
static byte[] |
|
static char[] |
|
static double[] |
|
static float[] |
|
static int[] |
|
static long[] |
|
static short[] |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static void |
|
static void |
|
static void |
|
static void |
|
static void |
|
static void |
|
static void |
|
static void |
|
static void |
|
static Map |
|
static Boolean[] |
|
static Byte[] |
|
static Double[] |
|
static Float[] |
|
static Integer[] |
|
static Long[] |
|
static Short[] |
|
static boolean[] |
|
static boolean[] |
|
static byte[] |
|
static byte[] |
|
static double[] |
|
static double[] |
|
static float[] |
|
static float[] |
|
static int[] |
|
static int[] |
|
static long[] |
|
static long[] |
|
static short[] |
|
static short[] |
|
static String |
|
static String |
|
public static final boolean[] EMPTY_BOOLEAN_ARRAY
An empty immutableboolean
array.
public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY
An empty immutableBoolean
array.
public static final byte[] EMPTY_BYTE_ARRAY
An empty immutablebyte
array.
public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY
An empty immutableByte
array.
public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY
An empty immutableCharacter
array.
public static final char[] EMPTY_CHAR_ARRAY
An empty immutablechar
array.
public static final Class[] EMPTY_CLASS_ARRAY
An empty immutableClass
array.
public static final double[] EMPTY_DOUBLE_ARRAY
An empty immutabledouble
array.
public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY
An empty immutableDouble
array.
public static final float[] EMPTY_FLOAT_ARRAY
An empty immutablefloat
array.
public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY
An empty immutableFloat
array.
public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY
An empty immutableInteger
array.
public static final int[] EMPTY_INT_ARRAY
An empty immutableint
array.
public static final long[] EMPTY_LONG_ARRAY
An empty immutablelong
array.
public static final Long[] EMPTY_LONG_OBJECT_ARRAY
An empty immutableLong
array.
public static final Object[] EMPTY_OBJECT_ARRAY
An empty immutableObject
array.
public static final short[] EMPTY_SHORT_ARRAY
An empty immutableshort
array.
public static final Short[] EMPTY_SHORT_OBJECT_ARRAY
An empty immutableShort
array.
public static final String[] EMPTY_STRING_ARRAY
An empty immutableString
array.
public ArrayUtils()
ArrayUtils instances should NOT be constructed in standard programming. Instead, the class should be used asArrayUtils.clone(new int[] {2})
. This constructor is public to permit tools that require a JavaBean instance to operate.
public static Object[] clone(Object[] array)
Shallow clones an array returning a typecast result and handlingnull
. The objecs in the array are not cloned, thus there is no special handling for multi-dimensional arrays. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to shallow clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static boolean[] clone(boolean[] array)
Clones an array returning a typecast result and handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static byte[] clone(byte[] array)
Clones an array returning a typecast result and handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static char[] clone(char[] array)
Clones an array returning a typecast result and handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static double[] clone(double[] array)
Clones an array returning a typecast result and handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static float[] clone(float[] array)
Clones an array returning a typecast result and handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static int[] clone(int[] array)
Clones an array returning a typecast result and handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static long[] clone(long[] array)
Clones an array returning a typecast result and handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static short[] clone(short[] array)
Clones an array returning a typecast result and handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- the array to clone, may benull
- Returns:
- the cloned array,
null
ifnull
input
public static boolean contains(Object[] array, Object objectToFind)
Checks if the object is in the given array. The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to search throughobjectToFind
- the object to find
- Returns:
true
if the array contains the object
public static boolean contains(boolean[] array, boolean valueToFind)
Checks if the value is in the given array. The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to search throughvalueToFind
- the value to find
- Returns:
true
if the array contains the object
public static boolean contains(byte[] array, byte valueToFind)
Checks if the value is in the given array. The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to search throughvalueToFind
- the value to find
- Returns:
true
if the array contains the object
public static boolean contains(double[] array, double valueToFind)
Checks if the value is in the given array. The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to search throughvalueToFind
- the value to find
- Returns:
true
if the array contains the object
public static boolean contains(double[] array, double valueToFind, double tolerance)
Checks if a value falling within the given tolerance is in the given array. If the array contains a value within the inclusive range defined by (value - tolerance) to (value + tolerance). The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to searchvalueToFind
- the value to findtolerance
- the array contains the tolerance of the search
- Returns:
- true if value falling within tolerance is in array
public static boolean contains(float[] array, float valueToFind)
Checks if the value is in the given array. The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to search throughvalueToFind
- the value to find
- Returns:
true
if the array contains the object
public static boolean contains(int[] array, int valueToFind)
Checks if the value is in the given array. The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to search throughvalueToFind
- the value to find
- Returns:
true
if the array contains the object
public static boolean contains(long[] array, long valueToFind)
Checks if the value is in the given array. The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to search throughvalueToFind
- the value to find
- Returns:
true
if the array contains the object
public static boolean contains(short[] array, short valueToFind)
Checks if the value is in the given array. The method returnsfalse
if anull
array is passed in.
- Parameters:
array
- the array to search throughvalueToFind
- the value to find
- Returns:
true
if the array contains the object
public static int hashCode(Object array)
Get a hashCode for an array handling multi-dimensional arrays correctly. Multi-dimensional primitive arrays are also handled correctly by this method.
- Parameters:
array
- the array to get a hashCode for, may benull
- Returns:
- a hashCode for the array, zero if null array input
public static int indexOf(Object[] array, Object objectToFind)
Find the index of the given object in the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
objectToFind
- the object to find, may benull
- Returns:
- the index of the object within the array,
-1
if not found ornull
array input
public static int indexOf(Object[] array, Object objectToFind, int startIndex)
Find the index of the given object in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return-1
.
- Parameters:
array
- the array to search through for the object, may benull
objectToFind
- the object to find, may benull
startIndex
- the index to start searching at
- Returns:
- the index of the object within the array starting at the index,
-1
if not found ornull
array input
public static int indexOf(boolean[] array, boolean valueToFind)
Find the index of the given value in the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to find
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(boolean[] array, boolean valueToFind, int startIndex)
Find the index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findstartIndex
- the index to start searching at
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(byte[] array, byte valueToFind)
Find the index of the given value in the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to find
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(byte[] array, byte valueToFind, int startIndex)
Find the index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findstartIndex
- the index to start searching at
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(double[] array, double valueToFind)
Find the index of the given value in the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to find
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(double[] array, double valueToFind, double tolerance)
Find the index of the given value within a given tolerance in the array. This method will return the index of the first value which falls between the region defined by valueToFind - tolerance and valueToFind + tolerance. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findtolerance
- tolerance of the search
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(double[] array, double valueToFind, int startIndex)
Find the index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findstartIndex
- the index to start searching at
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(double[] array, double valueToFind, int startIndex, double tolerance)
Find the index of the given value in the array starting at the given index. This method will return the index of the first value which falls between the region defined by valueToFind - tolerance and valueToFind + tolerance. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findstartIndex
- the index to start searching attolerance
- tolerance of the search
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(float[] array, float valueToFind)
Find the index of the given value in the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to find
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(float[] array, float valueToFind, int startIndex)
Find the index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findstartIndex
- the index to start searching at
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(int[] array, int valueToFind)
Find the index of the given value in the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to find
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(int[] array, int valueToFind, int startIndex)
Find the index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findstartIndex
- the index to start searching at
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(long[] array, long valueToFind)
Find the index of the given value in the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to find
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(long[] array, long valueToFind, int startIndex)
Find the index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findstartIndex
- the index to start searching at
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(short[] array, short valueToFind)
Find the index of the given value in the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to find
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int indexOf(short[] array, short valueToFind, int startIndex)
Find the index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findstartIndex
- the index to start searching at
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static boolean isEquals(Object array1, Object array2)
Compares two arrays, using equals(), handling multi-dimensional arrays correctly. Multi-dimensional primitive arrays are also handled correctly by this method.
- Parameters:
array1
- the array to get a hashCode for, may benull
array2
- the array to get a hashCode for, may benull
- Returns:
true
if the arrays are equal
public static boolean isSameLength(Object[] array1, Object[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
. Any multi-dimensional aspects of the arrays are ignored.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameLength(boolean[] array1, boolean[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameLength(byte[] array1, byte[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameLength(char[] array1, char[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameLength(double[] array1, double[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameLength(float[] array1, float[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameLength(int[] array1, int[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameLength(long[] array1, long[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameLength(short[] array1, short[] array2)
Checks whether two arrays are the same length, treatingnull
arrays as length0
.
- Parameters:
array1
- the first array, may benull
array2
- the second array, may benull
- Returns:
true
if length of arrays matches, treatingnull
as an empty array
public static boolean isSameType(Object array1, Object array2)
Checks whether two arrays are the same type taking into account multi-dimensional arrays.
- Parameters:
array1
- the first array, must not benull
array2
- the second array, must not benull
- Returns:
true
if type of arrays matches
public static int lastIndexOf(Object[] array, Object objectToFind)
Find the last index of the given object within the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to travers backwords looking for the object, may benull
objectToFind
- the object to find, may benull
- Returns:
- the last index of the object within the array,
-1
if not found ornull
array input
public static int lastIndexOf(Object[] array, Object objectToFind, int startIndex)
Find the last index of the given object in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex will return-1
. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
objectToFind
- the object to find, may benull
startIndex
- the start index to travers backwards from
- Returns:
- the last index of the object within the array,
-1
if not found ornull
array input
public static int lastIndexOf(boolean[] array, boolean valueToFind)
Find the last index of the given value within the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to travers backwords looking for the object, may benull
valueToFind
- the object to find
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(boolean[] array, boolean valueToFind, int startIndex)
Find the last index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(byte[] array, byte valueToFind)
Find the last index of the given value within the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to travers backwords looking for the object, may benull
valueToFind
- the object to find
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(byte[] array, byte valueToFind, int startIndex)
Find the last index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(double[] array, double valueToFind)
Find the last index of the given value within the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to travers backwords looking for the object, may benull
valueToFind
- the object to find
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(double[] array, double valueToFind, double tolerance)
Find the last index of the given value within a given tolerance in the array. This method will return the index of the last value which falls between the region defined by valueToFind - tolerance and valueToFind + tolerance. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to search through for the object, may benull
valueToFind
- the value to findtolerance
- tolerance of the search
- Returns:
- the index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(double[] array, double valueToFind, int startIndex)
Find the last index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(double[] array, double valueToFind, int startIndex, double tolerance)
Find the last index of the given value in the array starting at the given index. This method will return the index of the last value which falls between the region defined by valueToFind - tolerance and valueToFind + tolerance. This method returns-1
ifnull
array input. A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
valueToFind
- the value to findstartIndex
- the start index to travers backwards fromtolerance
- search for value within plus/minus this amount
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(float[] array, float valueToFind)
Find the last index of the given value within the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to travers backwords looking for the object, may benull
valueToFind
- the object to find
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(float[] array, float valueToFind, int startIndex)
Find the last index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(int[] array, int valueToFind)
Find the last index of the given value within the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to travers backwords looking for the object, may benull
valueToFind
- the object to find
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(int[] array, int valueToFind, int startIndex)
Find the last index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(long[] array, long valueToFind)
Find the last index of the given value within the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to travers backwords looking for the object, may benull
valueToFind
- the object to find
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(long[] array, long valueToFind, int startIndex)
Find the last index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(short[] array, short valueToFind)
Find the last index of the given value within the array. This method returns-1
ifnull
array input.
- Parameters:
array
- the array to travers backwords looking for the object, may benull
valueToFind
- the object to find
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static int lastIndexOf(short[] array, short valueToFind, int startIndex)
Find the last index of the given value in the array starting at the given index. This method returns-1
ifnull
array input. A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
- Parameters:
array
- the array to traverse for looking for the object, may benull
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
- Returns:
- the last index of the value within the array,
-1
if not found ornull
array input
public static void reverse(Object[] array)
Reverses the order of the given array. There is no special handling for multi-dimensional arrays. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static void reverse(boolean[] array)
Reverses the order of the given array. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static void reverse(byte[] array)
Reverses the order of the given array. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static void reverse(char[] array)
Reverses the order of the given array. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static void reverse(double[] array)
Reverses the order of the given array. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static void reverse(float[] array)
Reverses the order of the given array. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static void reverse(int[] array)
Reverses the order of the given array. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static void reverse(long[] array)
Reverses the order of the given array. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static void reverse(short[] array)
Reverses the order of the given array. This method does nothing ifnull
array input.
- Parameters:
array
- the array to reverse, may benull
public static Map toMap(Object[] array)
Converts the given array into ajava.util.Map
. Each element of the array must be either ajava.util.Map.Entry
or an Array, containing at least two elements, where the first element is used as key and the second as value. This method can be used to initialize:// Create a Map mapping colors. Map colorMap = MapUtils.toMap(new String[][] {{ {"RED", "#FF0000"}, {"GREEN", "#00FF00"}, {"BLUE", "#0000FF"}});This method returnsnull
ifnull
array input.
- Parameters:
array
- an array whose elements are either ajava.util.Map.Entry
or an Array containing at least two elements, may benull
- Returns:
- a
Map
that was created from the array
public static Boolean[] toObject(boolean[] array)
Converts an array of primitive booleans to objects. This method returnsnull
ifnull
array input.
- Parameters:
array
- aboolean
array
- Returns:
- a
Boolean
array,null
if null array input
public static Byte[] toObject(byte[] array)
Converts an array of primitive bytes to objects. This method returnsnull
ifnull
array input.
- Parameters:
array
- abyte
array
- Returns:
- a
Byte
array,null
if null array input
public static Double[] toObject(double[] array)
Converts an array of primitive doubles to objects. This method returnsnull
ifnull
array input.
- Parameters:
array
- adouble
array
- Returns:
- a
Double
array,null
if null array input
public static Float[] toObject(float[] array)
Converts an array of primitive floats to objects. This method returnsnull
ifnull
array input.
- Parameters:
array
- afloat
array
- Returns:
- a
Float
array,null
if null array input
public static Integer[] toObject(int[] array)
Converts an array of primitive ints to objects. This method returnsnull
ifnull
array input.
- Parameters:
array
- anint
array
- Returns:
- an
Integer
array,null
if null array input
public static Long[] toObject(long[] array)
Converts an array of primitive longs to objects. This method returnsnull
ifnull
array input.
- Parameters:
array
- along
array
- Returns:
- a
Long
array,null
if null array input
public static Short[] toObject(short[] array)
Converts an array of primitive shorts to objects. This method returnsnull
ifnull
array input.
- Parameters:
array
- ashort
array
- Returns:
- a
Short
array,null
if null array input
public static boolean[] toPrimitive(Boolean[] array)
Converts an array of object Booleans to primitives. This method returnsnull
ifnull
array input.
- Parameters:
array
- aBoolean
array, may benull
- Returns:
- a
boolean
array,null
if null array input
public static boolean[] toPrimitive(Boolean[] array, boolean valueForNull)
Converts an array of object Booleans to primitives handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- aBoolean
array, may benull
valueForNull
- the value to insert ifnull
found
- Returns:
- a
boolean
array,null
if null array input
public static byte[] toPrimitive(Byte[] array)
Converts an array of object Bytes to primitives. This method returnsnull
ifnull
array input.
- Parameters:
array
- aByte
array, may benull
- Returns:
- a
byte
array,null
if null array input
public static byte[] toPrimitive(Byte[] array, byte valueForNull)
Converts an array of object Bytes to primitives handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- aByte
array, may benull
valueForNull
- the value to insert ifnull
found
- Returns:
- a
byte
array,null
if null array input
public static double[] toPrimitive(Double[] array)
Converts an array of object Doubles to primitives. This method returnsnull
ifnull
array input.
- Parameters:
array
- aDouble
array, may benull
- Returns:
- a
double
array,null
if null array input
public static double[] toPrimitive(Double[] array, double valueForNull)
Converts an array of object Doubles to primitives handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- aDouble
array, may benull
valueForNull
- the value to insert ifnull
found
- Returns:
- a
double
array,null
if null array input
public static float[] toPrimitive(Float[] array)
Converts an array of object Floats to primitives. This method returnsnull
ifnull
array input.
- Parameters:
array
- aFloat
array, may benull
- Returns:
- a
float
array,null
if null array input
public static float[] toPrimitive(Float[] array, float valueForNull)
Converts an array of object Floats to primitives handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- aFloat
array, may benull
valueForNull
- the value to insert ifnull
found
- Returns:
- a
float
array,null
if null array input
public static int[] toPrimitive(Integer[] array)
Converts an array of object Integers to primitives. This method returnsnull
ifnull
array input.
- Parameters:
array
- aInteger
array, may benull
- Returns:
- an
int
array,null
if null array input
public static int[] toPrimitive(Integer[] array, int valueForNull)
Converts an array of object Integer to primitives handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- aInteger
array, may benull
valueForNull
- the value to insert ifnull
found
- Returns:
- an
int
array,null
if null array input
public static long[] toPrimitive(Long[] array)
Converts an array of object Longs to primitives. This method returnsnull
ifnull
array input.
- Parameters:
array
- aLong
array, may benull
- Returns:
- a
long
array,null
if null array input
public static long[] toPrimitive(Long[] array, long valueForNull)
Converts an array of object Long to primitives handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- aLong
array, may benull
valueForNull
- the value to insert ifnull
found
- Returns:
- a
long
array,null
if null array input
public static short[] toPrimitive(Short[] array)
Converts an array of object Shorts to primitives. This method returnsnull
ifnull
array input.
- Parameters:
array
- aShort
array, may benull
- Returns:
- a
byte
array,null
if null array input
public static short[] toPrimitive(Short[] array, short valueForNull)
Converts an array of object Short to primitives handlingnull
. This method returnsnull
ifnull
array input.
- Parameters:
array
- aShort
array, may benull
valueForNull
- the value to insert ifnull
found
- Returns:
- a
byte
array,null
if null array input
public static String toString(Object array)
Outputs an array as a String, treatingnull
as an empty array. Multi-dimensional arrays are handled correctly, including multi-dimensional primitive arrays. The format is that of Java source code, for example{a,b}
.
- Parameters:
array
- the array to get a toString for, may benull
- Returns:
- a String representation of the array, '{}' if null array input
public static String toString(Object array, String stringIfNull)
Outputs an array as a String handlingnull
s. Multi-dimensional arrays are handled correctly, including multi-dimensional primitive arrays. The format is that of Java source code, for example{a,b}
.
- Parameters:
array
- the array to get a toString for, may benull
stringIfNull
- the String to return if the array isnull
- Returns:
- a String representation of the array