|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.lang.ArrayUtils
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.
Field Summary | |
static boolean[] |
EMPTY_BOOLEAN_ARRAY
An empty immutable boolean array. |
static Boolean[] |
EMPTY_BOOLEAN_OBJECT_ARRAY
An empty immutable Boolean array. |
static byte[] |
EMPTY_BYTE_ARRAY
An empty immutable byte array. |
static Byte[] |
EMPTY_BYTE_OBJECT_ARRAY
An empty immutable Byte array. |
static char[] |
EMPTY_CHAR_ARRAY
An empty immutable char array. |
static Character[] |
EMPTY_CHARACTER_OBJECT_ARRAY
An empty immutable Character array. |
static Class[] |
EMPTY_CLASS_ARRAY
An empty immutable Class array. |
static double[] |
EMPTY_DOUBLE_ARRAY
An empty immutable double array. |
static Double[] |
EMPTY_DOUBLE_OBJECT_ARRAY
An empty immutable Double array. |
static float[] |
EMPTY_FLOAT_ARRAY
An empty immutable float array. |
static Float[] |
EMPTY_FLOAT_OBJECT_ARRAY
An empty immutable Float array. |
static int[] |
EMPTY_INT_ARRAY
An empty immutable int array. |
static Integer[] |
EMPTY_INTEGER_OBJECT_ARRAY
An empty immutable Integer array. |
static long[] |
EMPTY_LONG_ARRAY
An empty immutable long array. |
static Long[] |
EMPTY_LONG_OBJECT_ARRAY
An empty immutable Long array. |
static Object[] |
EMPTY_OBJECT_ARRAY
An empty immutable Object array. |
static short[] |
EMPTY_SHORT_ARRAY
An empty immutable short array. |
static Short[] |
EMPTY_SHORT_OBJECT_ARRAY
An empty immutable Short array. |
static String[] |
EMPTY_STRING_ARRAY
An empty immutable String array. |
Constructor Summary | |
ArrayUtils()
ArrayUtils instances should NOT be constructed in standard programming. |
Method Summary | |
static boolean[] |
clone(boolean[] array)
Clones an array returning a typecast result and handling null . |
static byte[] |
clone(byte[] array)
Clones an array returning a typecast result and handling null . |
static char[] |
clone(char[] array)
Clones an array returning a typecast result and handling null . |
static double[] |
clone(double[] array)
Clones an array returning a typecast result and handling null . |
static float[] |
clone(float[] array)
Clones an array returning a typecast result and handling null . |
static int[] |
clone(int[] array)
Clones an array returning a typecast result and handling null . |
static long[] |
clone(long[] array)
Clones an array returning a typecast result and handling null . |
static Object[] |
clone(Object[] array)
Shallow clones an array returning a typecast result and handling null . |
static short[] |
clone(short[] array)
Clones an array returning a typecast result and handling null . |
static boolean |
contains(boolean[] array,
boolean valueToFind)
Checks if the value is in the given array. |
static boolean |
contains(byte[] array,
byte valueToFind)
Checks if the value is in the given array. |
static boolean |
contains(double[] array,
double valueToFind)
Checks if the value is in the given array. |
static boolean |
contains(double[] array,
double valueToFind,
double tolerance)
Checks if a value falling within the given tolerance is in the given array. |
static boolean |
contains(float[] array,
float valueToFind)
Checks if the value is in the given array. |
static boolean |
contains(int[] array,
int valueToFind)
Checks if the value is in the given array. |
static boolean |
contains(long[] array,
long valueToFind)
Checks if the value is in the given array. |
static boolean |
contains(Object[] array,
Object objectToFind)
Checks if the object is in the given array. |
static boolean |
contains(short[] array,
short valueToFind)
Checks if the value is in the given array. |
static int |
hashCode(Object array)
Get a hashCode for an array handling multi-dimensional arrays correctly. |
static int |
indexOf(boolean[] array,
boolean valueToFind)
Find the index of the given value in the array. |
static int |
indexOf(boolean[] array,
boolean valueToFind,
int startIndex)
Find the index of the given value in the array starting at the given index. |
static int |
indexOf(byte[] array,
byte valueToFind)
Find the index of the given value in the array. |
static int |
indexOf(byte[] array,
byte valueToFind,
int startIndex)
Find the index of the given value in the array starting at the given index. |
static int |
indexOf(double[] array,
double valueToFind)
Find the index of the given value in the array. |
static int |
indexOf(double[] array,
double valueToFind,
double tolerance)
Find the index of the given value within a given tolerance in the array. |
static int |
indexOf(double[] array,
double valueToFind,
int startIndex)
Find the index of the given value in the array starting at the given index. |
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. |
static int |
indexOf(float[] array,
float valueToFind)
Find the index of the given value in the array. |
static int |
indexOf(float[] array,
float valueToFind,
int startIndex)
Find the index of the given value in the array starting at the given index. |
static int |
indexOf(int[] array,
int valueToFind)
Find the index of the given value in the array. |
static int |
indexOf(int[] array,
int valueToFind,
int startIndex)
Find the index of the given value in the array starting at the given index. |
static int |
indexOf(long[] array,
long valueToFind)
Find the index of the given value in the array. |
static int |
indexOf(long[] array,
long valueToFind,
int startIndex)
Find the index of the given value in the array starting at the given index. |
static int |
indexOf(Object[] array,
Object objectToFind)
Find the index of the given object in the array. |
static int |
indexOf(Object[] array,
Object objectToFind,
int startIndex)
Find the index of the given object in the array starting at the given index. |
static int |
indexOf(short[] array,
short valueToFind)
Find the index of the given value in the array. |
static int |
indexOf(short[] array,
short valueToFind,
int startIndex)
Find the index of the given value in the array starting at the given index. |
static boolean |
isEquals(Object array1,
Object array2)
Compares two arrays, using equals(), handling multi-dimensional arrays correctly. |
static boolean |
isSameLength(boolean[] array1,
boolean[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameLength(byte[] array1,
byte[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameLength(char[] array1,
char[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameLength(double[] array1,
double[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameLength(float[] array1,
float[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameLength(int[] array1,
int[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameLength(long[] array1,
long[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameLength(Object[] array1,
Object[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameLength(short[] array1,
short[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static boolean |
isSameType(Object array1,
Object array2)
Checks whether two arrays are the same type taking into account multi-dimensional arrays. |
static int |
lastIndexOf(boolean[] array,
boolean valueToFind)
Find the last index of the given value within the array. |
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. |
static int |
lastIndexOf(byte[] array,
byte valueToFind)
Find the last index of the given value within the array. |
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. |
static int |
lastIndexOf(double[] array,
double valueToFind)
Find the last index of the given value within the array. |
static int |
lastIndexOf(double[] array,
double valueToFind,
double tolerance)
Find the last index of the given value within a given tolerance in the array. |
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. |
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. |
static int |
lastIndexOf(float[] array,
float valueToFind)
Find the last index of the given value within the array. |
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. |
static int |
lastIndexOf(int[] array,
int valueToFind)
Find the last index of the given value within the array. |
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. |
static int |
lastIndexOf(long[] array,
long valueToFind)
Find the last index of the given value within the array. |
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. |
static int |
lastIndexOf(Object[] array,
Object objectToFind)
Find the last index of the given object within the array. |
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. |
static int |
lastIndexOf(short[] array,
short valueToFind)
Find the last index of the given value within the array. |
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. |
static void |
reverse(boolean[] array)
Reverses the order of the given array. |
static void |
reverse(byte[] array)
Reverses the order of the given array. |
static void |
reverse(char[] array)
Reverses the order of the given array. |
static void |
reverse(double[] array)
Reverses the order of the given array. |
static void |
reverse(float[] array)
Reverses the order of the given array. |
static void |
reverse(int[] array)
Reverses the order of the given array. |
static void |
reverse(long[] array)
Reverses the order of the given array. |
static void |
reverse(Object[] array)
Reverses the order of the given array. |
static void |
reverse(short[] array)
Reverses the order of the given array. |
static Map |
toMap(Object[] array)
Converts the given array into a Map . |
static Boolean[] |
toObject(boolean[] array)
Converts an array of primitive booleans to objects. |
static Byte[] |
toObject(byte[] array)
Converts an array of primitive bytes to objects. |
static Double[] |
toObject(double[] array)
Converts an array of primitive doubles to objects. |
static Float[] |
toObject(float[] array)
Converts an array of primitive floats to objects. |
static Integer[] |
toObject(int[] array)
Converts an array of primitive ints to objects. |
static Long[] |
toObject(long[] array)
Converts an array of primitive longs to objects. |
static Short[] |
toObject(short[] array)
Converts an array of primitive shorts to objects. |
static boolean[] |
toPrimitive(Boolean[] array)
Converts an array of object Booleans to primitives. |
static boolean[] |
toPrimitive(Boolean[] array,
boolean valueForNull)
Converts an array of object Booleans to primitives handling null . |
static byte[] |
toPrimitive(Byte[] array)
Converts an array of object Bytes to primitives. |
static byte[] |
toPrimitive(Byte[] array,
byte valueForNull)
Converts an array of object Bytes to primitives handling null . |
static double[] |
toPrimitive(Double[] array)
Converts an array of object Doubles to primitives. |
static double[] |
toPrimitive(Double[] array,
double valueForNull)
Converts an array of object Doubles to primitives handling null . |
static float[] |
toPrimitive(Float[] array)
Converts an array of object Floats to primitives. |
static float[] |
toPrimitive(Float[] array,
float valueForNull)
Converts an array of object Floats to primitives handling null . |
static int[] |
toPrimitive(Integer[] array)
Converts an array of object Integers to primitives. |
static int[] |
toPrimitive(Integer[] array,
int valueForNull)
Converts an array of object Integer to primitives handling null . |
static long[] |
toPrimitive(Long[] array)
Converts an array of object Longs to primitives. |
static long[] |
toPrimitive(Long[] array,
long valueForNull)
Converts an array of object Long to primitives handling null . |
static short[] |
toPrimitive(Short[] array)
Converts an array of object Shorts to primitives. |
static short[] |
toPrimitive(Short[] array,
short valueForNull)
Converts an array of object Short to primitives handling null . |
static String |
toString(Object array)
Outputs an array as a String, treating null as an empty array. |
static String |
toString(Object array,
String stringIfNull)
Outputs an array as a String handling null s. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final Object[] EMPTY_OBJECT_ARRAY
Object
array.
public static final Class[] EMPTY_CLASS_ARRAY
Class
array.
public static final String[] EMPTY_STRING_ARRAY
String
array.
public static final long[] EMPTY_LONG_ARRAY
long
array.
public static final Long[] EMPTY_LONG_OBJECT_ARRAY
Long
array.
public static final int[] EMPTY_INT_ARRAY
int
array.
public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY
Integer
array.
public static final short[] EMPTY_SHORT_ARRAY
short
array.
public static final Short[] EMPTY_SHORT_OBJECT_ARRAY
Short
array.
public static final byte[] EMPTY_BYTE_ARRAY
byte
array.
public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY
Byte
array.
public static final double[] EMPTY_DOUBLE_ARRAY
double
array.
public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY
Double
array.
public static final float[] EMPTY_FLOAT_ARRAY
float
array.
public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY
Float
array.
public static final boolean[] EMPTY_BOOLEAN_ARRAY
boolean
array.
public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY
Boolean
array.
public static final char[] EMPTY_CHAR_ARRAY
char
array.
public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY
Character
array.
Constructor Detail |
public ArrayUtils()
ArrayUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as ArrayUtils.clone(new int[] {2})
.
This constructor is public to permit tools that require a JavaBean instance to operate.
Method Detail |
public static String toString(Object array)
Outputs an array as a String, treating null
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}
.
array
- the array to get a toString for, may be null
public static String toString(Object array, String stringIfNull)
Outputs an array as a String handling null
s.
Multi-dimensional arrays are handled correctly, including multi-dimensional primitive arrays.
The format is that of Java source code, for example {a,b}
.
array
- the array to get a toString for, may be null
stringIfNull
- the String to return if the array is null
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.
array
- the array to get a hashCode for, may be null
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.
array1
- the array to get a hashCode for, may be null
array2
- the array to get a hashCode for, may be null
true
if the arrays are equalpublic static Map toMap(Object[] array)
Converts the given array into a Map
. Each element of the array
must be either a 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 returns null
if null
array input.
array
- an array whose elements are either a Map.Entry
or
an Array containing at least two elements, may be null
Map
that was created from the array
IllegalArgumentException
- if one element of this Array is
itself an Array containing less then two elements
IllegalArgumentException
- if the array contains elements other
than Map.Entry
and an Arraypublic static Object[] clone(Object[] array)
Shallow clones an array returning a typecast result and handling
null
.
The objecs in the array are not cloned, thus there is no special handling for multi-dimensional arrays.
This method returns null
if null
array input.
array
- the array to shallow clone, may be null
null
if null
inputpublic static long[] clone(long[] array)
Clones an array returning a typecast result and handling
null
.
This method returns null
if null
array input.
array
- the array to clone, may be null
null
if null
inputpublic static int[] clone(int[] array)
Clones an array returning a typecast result and handling
null
.
This method returns null
if null
array input.
array
- the array to clone, may be null
null
if null
inputpublic static short[] clone(short[] array)
Clones an array returning a typecast result and handling
null
.
This method returns null
if null
array input.
array
- the array to clone, may be null
null
if null
inputpublic static char[] clone(char[] array)
Clones an array returning a typecast result and handling
null
.
This method returns null
if null
array input.
array
- the array to clone, may be null
null
if null
inputpublic static byte[] clone(byte[] array)
Clones an array returning a typecast result and handling
null
.
This method returns null
if null
array input.
array
- the array to clone, may be null
null
if null
inputpublic static double[] clone(double[] array)
Clones an array returning a typecast result and handling
null
.
This method returns null
if null
array input.
array
- the array to clone, may be null
null
if null
inputpublic static float[] clone(float[] array)
Clones an array returning a typecast result and handling
null
.
This method returns null
if null
array input.
array
- the array to clone, may be null
null
if null
inputpublic static boolean[] clone(boolean[] array)
Clones an array returning a typecast result and handling
null
.
This method returns null
if null
array input.
array
- the array to clone, may be null
null
if null
inputpublic static boolean isSameLength(Object[] array1, Object[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
Any multi-dimensional aspects of the arrays are ignored.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameLength(long[] array1, long[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameLength(int[] array1, int[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameLength(short[] array1, short[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameLength(char[] array1, char[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameLength(byte[] array1, byte[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameLength(double[] array1, double[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameLength(float[] array1, float[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameLength(boolean[] array1, boolean[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static boolean isSameType(Object array1, Object array2)
Checks whether two arrays are the same type taking into account multi-dimensional arrays.
array1
- the first array, must not be null
array2
- the second array, must not be null
true
if type of arrays matches
IllegalArgumentException
- if either array is null
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 if null
array input.
array
- the array to reverse, may be null
public static void reverse(long[] array)
Reverses the order of the given array.
This method does nothing if null
array input.
array
- the array to reverse, may be null
public static void reverse(int[] array)
Reverses the order of the given array.
This method does nothing if null
array input.
array
- the array to reverse, may be null
public static void reverse(short[] array)
Reverses the order of the given array.
This method does nothing if null
array input.
array
- the array to reverse, may be null
public static void reverse(char[] array)
Reverses the order of the given array.
This method does nothing if null
array input.
array
- the array to reverse, may be null
public static void reverse(byte[] array)
Reverses the order of the given array.
This method does nothing if null
array input.
array
- the array to reverse, may be null
public static void reverse(double[] array)
Reverses the order of the given array.
This method does nothing if null
array input.
array
- the array to reverse, may be null
public static void reverse(float[] array)
Reverses the order of the given array.
This method does nothing if null
array input.
array
- the array to reverse, may be null
public static void reverse(boolean[] array)
Reverses the order of the given array.
This method does nothing if null
array input.
array
- the array to reverse, may be null
public static int indexOf(Object[] array, Object objectToFind)
Find the index of the given object in the array.
This method returns -1
if null
array input.
array
- the array to search through for the object, may be null
objectToFind
- the object to find, may be null
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array
length will return -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 at
-1
if not found or null
array inputpublic static int lastIndexOf(Object[] array, Object objectToFind)
Find the last index of the given object within the array.
This method returns -1
if null
array input.
array
- the array to travers backwords looking for the object, may be null
objectToFind
- the object to find, may be null
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1
. A startIndex larger than
the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
objectToFind
- the object to find, may be null
startIndex
- the start index to travers backwards from
-1
if not found or null
array inputpublic static boolean contains(Object[] array, 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 find
true
if the array contains the objectpublic static int indexOf(long[] array, long valueToFind)
Find the index of the given value in the array.
This method returns -1
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
array
- the array to search through for the object, may be null
valueToFind
- the value to findstartIndex
- the index to start searching at
-1
if not found or null
array inputpublic static int lastIndexOf(long[] array, long valueToFind)
Find the last index of the given value within the array.
This method returns -1
if null
array input.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
-1
if not found or null
array inputpublic static boolean contains(long[] array, long valueToFind)
Checks if the value is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughvalueToFind
- the value to find
true
if the array contains the objectpublic static int indexOf(int[] array, int valueToFind)
Find the index of the given value in the array.
This method returns -1
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
array
- the array to search through for the object, may be null
valueToFind
- the value to findstartIndex
- the index to start searching at
-1
if not found or null
array inputpublic static int lastIndexOf(int[] array, int valueToFind)
Find the last index of the given value within the array.
This method returns -1
if null
array input.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
-1
if not found or null
array inputpublic static boolean contains(int[] array, int valueToFind)
Checks if the value is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughvalueToFind
- the value to find
true
if the array contains the objectpublic static int indexOf(short[] array, short valueToFind)
Find the index of the given value in the array.
This method returns -1
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
array
- the array to search through for the object, may be null
valueToFind
- the value to findstartIndex
- the index to start searching at
-1
if not found or null
array inputpublic static int lastIndexOf(short[] array, short valueToFind)
Find the last index of the given value within the array.
This method returns -1
if null
array input.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
-1
if not found or null
array inputpublic static boolean contains(short[] array, short valueToFind)
Checks if the value is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughvalueToFind
- the value to find
true
if the array contains the objectpublic static int indexOf(byte[] array, byte valueToFind)
Find the index of the given value in the array.
This method returns -1
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
array
- the array to search through for the object, may be null
valueToFind
- the value to findstartIndex
- the index to start searching at
-1
if not found or null
array inputpublic static int lastIndexOf(byte[] array, byte valueToFind)
Find the last index of the given value within the array.
This method returns -1
if null
array input.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
-1
if not found or null
array inputpublic static boolean contains(byte[] array, byte valueToFind)
Checks if the value is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughvalueToFind
- the value to find
true
if the array contains the objectpublic static int indexOf(double[] array, double valueToFind)
Find the index of the given value in the array.
This method returns -1
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to find
-1
if not found or null
array inputpublic 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
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to findtolerance
- tolerance of the search
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
array
- the array to search through for the object, may be null
valueToFind
- the value to findstartIndex
- the index to start searching at
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
array
- the array to search through for the object, may be null
valueToFind
- the value to findstartIndex
- the index to start searching attolerance
- tolerance of the search
-1
if not found or null
array inputpublic static int lastIndexOf(double[] array, double valueToFind)
Find the last index of the given value within the array.
This method returns -1
if null
array input.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to find
-1
if not found or null
array inputpublic 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
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to findtolerance
- tolerance of the search
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index to travers backwards fromtolerance
- search for value within plus/minus this amount
-1
if not found or null
array inputpublic static boolean contains(double[] array, double valueToFind)
Checks if the value is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughvalueToFind
- the value to find
true
if the array contains the objectpublic 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 returns false
if a null
array
is passed in.
array
- the array to searchvalueToFind
- the value to findtolerance
- the array contains the tolerance of the search
public static int indexOf(float[] array, float valueToFind)
Find the index of the given value in the array.
This method returns -1
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
array
- the array to search through for the object, may be null
valueToFind
- the value to findstartIndex
- the index to start searching at
-1
if not found or null
array inputpublic static int lastIndexOf(float[] array, float valueToFind)
Find the last index of the given value within the array.
This method returns -1
if null
array input.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
-1
if not found or null
array inputpublic static boolean contains(float[] array, float valueToFind)
Checks if the value is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughvalueToFind
- the value to find
true
if the array contains the objectpublic static int indexOf(boolean[] array, boolean valueToFind)
Find the index of the given value in the array.
This method returns -1
if null
array input.
array
- the array to search through for the object, may be null
valueToFind
- the value to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex is treated as zero. A startIndex larger than the array length will return -1.
array
- the array to search through for the object, may be null
valueToFind
- the value to findstartIndex
- the index to start searching at
-1
if not found or null
array inputpublic static int lastIndexOf(boolean[] array, boolean valueToFind)
Find the last index of the given value within the array.
This method returns -1
if null
array input.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to find
-1
if not found or null
array inputpublic 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
if null
array input.
A negative startIndex will return -1. A startIndex larger than the array length will search from the end of the array.
array
- the array to traverse for looking for the object, may be null
valueToFind
- the value to findstartIndex
- the start index to travers backwards from
-1
if not found or null
array inputpublic static boolean contains(boolean[] array, boolean valueToFind)
Checks if the value is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughvalueToFind
- the value to find
true
if the array contains the objectpublic static long[] toPrimitive(Long[] array)
Converts an array of object Longs to primitives.
This method returns null
if null
array input.
array
- a Long
array, may be null
long
array, null
if null array input
NullPointerException
- if array content is null
public static long[] toPrimitive(Long[] array, long valueForNull)
Converts an array of object Long to primitives handling null
.
This method returns null
if null
array input.
array
- a Long
array, may be null
valueForNull
- the value to insert if null
found
long
array, null
if null array inputpublic static Long[] toObject(long[] array)
Converts an array of primitive longs to objects.
This method returns null
if null
array input.
array
- a long
array
Long
array, null
if null array inputpublic static int[] toPrimitive(Integer[] array)
Converts an array of object Integers to primitives.
This method returns null
if null
array input.
array
- a Integer
array, may be null
int
array, null
if null array input
NullPointerException
- if array content is null
public static int[] toPrimitive(Integer[] array, int valueForNull)
Converts an array of object Integer to primitives handling null
.
This method returns null
if null
array input.
array
- a Integer
array, may be null
valueForNull
- the value to insert if null
found
int
array, null
if null array inputpublic static Integer[] toObject(int[] array)
Converts an array of primitive ints to objects.
This method returns null
if null
array input.
array
- an int
array
Integer
array, null
if null array inputpublic static short[] toPrimitive(Short[] array)
Converts an array of object Shorts to primitives.
This method returns null
if null
array input.
array
- a Short
array, may be null
byte
array, null
if null array input
NullPointerException
- if array content is null
public static short[] toPrimitive(Short[] array, short valueForNull)
Converts an array of object Short to primitives handling null
.
This method returns null
if null
array input.
array
- a Short
array, may be null
valueForNull
- the value to insert if null
found
byte
array, null
if null array inputpublic static Short[] toObject(short[] array)
Converts an array of primitive shorts to objects.
This method returns null
if null
array input.
array
- a short
array
Short
array, null
if null array inputpublic static byte[] toPrimitive(Byte[] array)
Converts an array of object Bytes to primitives.
This method returns null
if null
array input.
array
- a Byte
array, may be null
byte
array, null
if null array input
NullPointerException
- if array content is null
public static byte[] toPrimitive(Byte[] array, byte valueForNull)
Converts an array of object Bytes to primitives handling null
.
This method returns null
if null
array input.
array
- a Byte
array, may be null
valueForNull
- the value to insert if null
found
byte
array, null
if null array inputpublic static Byte[] toObject(byte[] array)
Converts an array of primitive bytes to objects.
This method returns null
if null
array input.
array
- a byte
array
Byte
array, null
if null array inputpublic static double[] toPrimitive(Double[] array)
Converts an array of object Doubles to primitives.
This method returns null
if null
array input.
array
- a Double
array, may be null
double
array, null
if null array input
NullPointerException
- if array content is null
public static double[] toPrimitive(Double[] array, double valueForNull)
Converts an array of object Doubles to primitives handling null
.
This method returns null
if null
array input.
array
- a Double
array, may be null
valueForNull
- the value to insert if null
found
double
array, null
if null array inputpublic static Double[] toObject(double[] array)
Converts an array of primitive doubles to objects.
This method returns null
if null
array input.
array
- a double
array
Double
array, null
if null array inputpublic static float[] toPrimitive(Float[] array)
Converts an array of object Floats to primitives.
This method returns null
if null
array input.
array
- a Float
array, may be null
float
array, null
if null array input
NullPointerException
- if array content is null
public static float[] toPrimitive(Float[] array, float valueForNull)
Converts an array of object Floats to primitives handling null
.
This method returns null
if null
array input.
array
- a Float
array, may be null
valueForNull
- the value to insert if null
found
float
array, null
if null array inputpublic static Float[] toObject(float[] array)
Converts an array of primitive floats to objects.
This method returns null
if null
array input.
array
- a float
array
Float
array, null
if null array inputpublic static boolean[] toPrimitive(Boolean[] array)
Converts an array of object Booleans to primitives.
This method returns null
if null
array input.
array
- a Boolean
array, may be null
boolean
array, null
if null array input
NullPointerException
- if array content is null
public static boolean[] toPrimitive(Boolean[] array, boolean valueForNull)
Converts an array of object Booleans to primitives handling null
.
This method returns null
if null
array input.
array
- a Boolean
array, may be null
valueForNull
- the value to insert if null
found
boolean
array, null
if null array inputpublic static Boolean[] toObject(boolean[] array)
Converts an array of primitive booleans to objects.
This method returns null
if null
array input.
array
- a boolean
array
Boolean
array, null
if null array input
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |