public abstract class ArrayUtils extends 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.
#ThreadSafe#
Modifier and Type | Field and Description |
---|---|
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. |
static int |
INDEX_NOT_FOUND
The index value when an element is not found in a list or array:
-1 . |
Constructor and Description |
---|
ArrayUtils()
ArrayUtils instances should NOT be constructed in standard programming.
|
Modifier and Type | Method and Description |
---|---|
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(char[] array,
char 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(short[] array,
short valueToFind)
Checks if the value is in the given array.
|
static int |
indexOf(boolean[] array,
boolean valueToFind)
Finds the index of the given value in the array.
|
static int |
indexOf(boolean[] array,
boolean valueToFind,
int startIndex)
Finds the index of the given value in the array starting at the given index.
|
static int |
indexOf(byte[] array,
byte valueToFind)
Finds the index of the given value in the array.
|
static int |
indexOf(byte[] array,
byte valueToFind,
int startIndex)
Finds the index of the given value in the array starting at the given index.
|
static int |
indexOf(char[] array,
char valueToFind)
Finds the index of the given value in the array.
|
static int |
indexOf(char[] array,
char valueToFind,
int startIndex)
Finds the index of the given value in the array starting at the given index.
|
static int |
indexOf(double[] array,
double valueToFind)
Finds the index of the given value in the array.
|
static int |
indexOf(double[] array,
double valueToFind,
double tolerance)
Finds the index of the given value within a given tolerance in the array.
|
static int |
indexOf(double[] array,
double valueToFind,
int startIndex)
Finds 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)
Finds the index of the given value in the array starting at the given index.
|
static int |
indexOf(float[] array,
float valueToFind)
Finds the index of the given value in the array.
|
static int |
indexOf(float[] array,
float valueToFind,
int startIndex)
Finds the index of the given value in the array starting at the given index.
|
static int |
indexOf(int[] array,
int valueToFind)
Finds the index of the given value in the array.
|
static int |
indexOf(int[] array,
int valueToFind,
int startIndex)
Finds the index of the given value in the array starting at the given index.
|
static int |
indexOf(long[] array,
long valueToFind)
Finds the index of the given value in the array.
|
static int |
indexOf(long[] array,
long valueToFind,
int startIndex)
Finds the index of the given value in the array starting at the given index.
|
static int |
indexOf(short[] array,
short valueToFind)
Finds the index of the given value in the array.
|
static int |
indexOf(short[] array,
short valueToFind,
int startIndex)
Finds the index of the given value in the array starting at the given index.
|
static boolean |
isEmpty(boolean[] array)
Checks if an array of primitive booleans is empty or
null . |
static boolean |
isEmpty(byte[] array)
Checks if an array of primitive bytes is empty or
null . |
static boolean |
isEmpty(char[] array)
Checks if an array of primitive chars is empty or
null . |
static boolean |
isEmpty(double[] array)
Checks if an array of primitive doubles is empty or
null . |
static boolean |
isEmpty(float[] array)
Checks if an array of primitive floats is empty or
null . |
static boolean |
isEmpty(int[] array)
Checks if an array of primitive ints is empty or
null . |
static boolean |
isEmpty(long[] array)
Checks if an array of primitive longs is empty or
null . |
static boolean |
isEmpty(Object[] array)
Checks if an array of Objects is empty or
null . |
static boolean |
isEmpty(short[] array)
Checks if an array of primitive shorts is empty or
null . |
static boolean |
isNotEmpty(boolean[] array)
Checks if an array of primitive booleans is not empty or not
null . |
static boolean |
isNotEmpty(byte[] array)
Checks if an array of primitive bytes is not empty or not
null . |
static boolean |
isNotEmpty(char[] array)
Checks if an array of primitive chars is not empty or not
null . |
static boolean |
isNotEmpty(double[] array)
Checks if an array of primitive doubles is not empty or not
null . |
static boolean |
isNotEmpty(float[] array)
Checks if an array of primitive floats is not empty or not
null . |
static boolean |
isNotEmpty(int[] array)
Checks if an array of primitive ints is not empty or not
null . |
static boolean |
isNotEmpty(long[] array)
Checks if an array of primitive longs is not empty or not
null . |
static boolean |
isNotEmpty(short[] array)
Checks if an array of primitive shorts is not empty or not
null . |
static <T> boolean |
isNotEmpty(T[] array)
Checks if an array of Objects is not empty or not
null . |
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)
Finds the last index of the given value within the array.
|
static int |
lastIndexOf(boolean[] array,
boolean valueToFind,
int startIndex)
Finds the last index of the given value in the array starting at the given index.
|
static int |
lastIndexOf(byte[] array,
byte valueToFind)
Finds the last index of the given value within the array.
|
static int |
lastIndexOf(byte[] array,
byte valueToFind,
int startIndex)
Finds the last index of the given value in the array starting at the given index.
|
static int |
lastIndexOf(char[] array,
char valueToFind)
Finds the last index of the given value within the array.
|
static int |
lastIndexOf(char[] array,
char valueToFind,
int startIndex)
Finds the last index of the given value in the array starting at the given index.
|
static int |
lastIndexOf(double[] array,
double valueToFind)
Finds the last index of the given value within the array.
|
static int |
lastIndexOf(double[] array,
double valueToFind,
double tolerance)
Finds the last index of the given value within a given tolerance in the array.
|
static int |
lastIndexOf(double[] array,
double valueToFind,
int startIndex)
Finds 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)
Finds the last index of the given value in the array starting at the given index.
|
static int |
lastIndexOf(float[] array,
float valueToFind)
Finds the last index of the given value within the array.
|
static int |
lastIndexOf(float[] array,
float valueToFind,
int startIndex)
Finds the last index of the given value in the array starting at the given index.
|
static int |
lastIndexOf(int[] array,
int valueToFind)
Finds the last index of the given value within the array.
|
static int |
lastIndexOf(int[] array,
int valueToFind,
int startIndex)
Finds the last index of the given value in the array starting at the given index.
|
static int |
lastIndexOf(long[] array,
long valueToFind)
Finds the last index of the given value within the array.
|
static int |
lastIndexOf(long[] array,
long valueToFind,
int startIndex)
Finds the last index of the given value in the array starting at the given index.
|
static int |
lastIndexOf(short[] array,
short valueToFind)
Finds the last index of the given value within the array.
|
static int |
lastIndexOf(short[] array,
short valueToFind,
int startIndex)
Finds the last index of the given value in the array starting at the given index.
|
static boolean[] |
nullToEmpty(boolean[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Boolean[] |
nullToEmpty(Boolean[] array)
Defensive programming technique to change a
null reference to an empty one. |
static byte[] |
nullToEmpty(byte[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Byte[] |
nullToEmpty(Byte[] array)
Defensive programming technique to change a
null reference to an empty one. |
static char[] |
nullToEmpty(char[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Character[] |
nullToEmpty(Character[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Class<?>[] |
nullToEmpty(Class<?>[] array)
Defensive programming technique to change a
null reference to an empty one. |
static double[] |
nullToEmpty(double[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Double[] |
nullToEmpty(Double[] array)
Defensive programming technique to change a
null reference to an empty one. |
static float[] |
nullToEmpty(float[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Float[] |
nullToEmpty(Float[] array)
Defensive programming technique to change a
null reference to an empty one. |
static int[] |
nullToEmpty(int[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Integer[] |
nullToEmpty(Integer[] array)
Defensive programming technique to change a
null reference to an empty one. |
static long[] |
nullToEmpty(long[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Long[] |
nullToEmpty(Long[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Object[] |
nullToEmpty(Object[] array)
Defensive programming technique to change a
null reference to an empty one. |
static short[] |
nullToEmpty(short[] array)
Defensive programming technique to change a
null reference to an empty one. |
static Short[] |
nullToEmpty(Short[] array)
Defensive programming technique to change a
null reference to an empty one. |
static String[] |
nullToEmpty(String[] array)
Defensive programming technique to change a
null reference to an empty one. |
static void |
reverse(boolean[] array)
Reverses the order of the given array.
|
static void |
reverse(boolean[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static void |
reverse(byte[] array)
Reverses the order of the given array.
|
static void |
reverse(byte[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static void |
reverse(char[] array)
Reverses the order of the given array.
|
static void |
reverse(char[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static void |
reverse(double[] array)
Reverses the order of the given array.
|
static void |
reverse(double[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static void |
reverse(float[] array)
Reverses the order of the given array.
|
static void |
reverse(float[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static void |
reverse(int[] array)
Reverses the order of the given array.
|
static void |
reverse(int[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static void |
reverse(long[] array)
Reverses the order of the given array.
|
static void |
reverse(long[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static void |
reverse(Object[] array)
Reverses the order of the given array.
|
static void |
reverse(Object[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static void |
reverse(short[] array)
Reverses the order of the given array.
|
static void |
reverse(short[] array,
int startIndexInclusive,
int endIndexExclusive)
Reverses the order of the given array in the given range.
|
static boolean[] |
subarray(boolean[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new
boolean array containing the elements between the start and end indices. |
static byte[] |
subarray(byte[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new
byte array containing the elements between the start and end indices. |
static char[] |
subarray(char[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new
char array containing the elements between the start and end indices. |
static double[] |
subarray(double[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new
double array containing the elements between the start and end indices. |
static float[] |
subarray(float[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new
float array containing the elements between the start and end indices. |
static int[] |
subarray(int[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new
int array containing the elements between the start and end indices. |
static long[] |
subarray(long[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new
long array containing the elements between the start and end indices. |
static short[] |
subarray(short[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new
short array containing the elements between the start and end indices. |
static Map<Object,Object> |
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 Character[] |
toObject(char[] array)
Converts an array of primitive chars 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 char[] |
toPrimitive(Character[] array)
Converts an array of object Characters to primitives.
|
static char[] |
toPrimitive(Character[] array,
char valueForNull)
Converts an array of object Character 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 . |
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.public 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
.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.
public static Map<Object,Object> 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
for a null
input array.
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 arrayIllegalArgumentException
- if one element of this Array is itself an Array containing
less then two elementsIllegalArgumentException
- if the array contains elements other than
Map.Entry
and an Arraypublic static Object[] nullToEmpty(Object[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Class<?>[] nullToEmpty(Class<?>[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static String[] nullToEmpty(String[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static long[] nullToEmpty(long[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static int[] nullToEmpty(int[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static short[] nullToEmpty(short[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static char[] nullToEmpty(char[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static byte[] nullToEmpty(byte[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static double[] nullToEmpty(double[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static float[] nullToEmpty(float[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static boolean[] nullToEmpty(boolean[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Long[] nullToEmpty(Long[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Integer[] nullToEmpty(Integer[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Short[] nullToEmpty(Short[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Character[] nullToEmpty(Character[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Byte[] nullToEmpty(Byte[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Double[] nullToEmpty(Double[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Float[] nullToEmpty(Float[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static Boolean[] nullToEmpty(Boolean[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with the empty
public static
references in this class.
array
- the array to check for null
or emptypublic static
empty array if null
or empty inputpublic static long[] subarray(long[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new long
array containing the elements between the start and end indices.
The start index is inclusive, the end index exclusive. Null array input produces null output.
array
- the arraystartIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in an empty array.endIndexExclusive
- elements up to endIndex-1 are present in the returned subarray.
Undervalue (< startIndex) produces empty array, overvalue (>array.length) is
demoted to array length.Arrays.copyOfRange(long[], int, int)
public static int[] subarray(int[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new int
array containing the elements between the start and end indices.
The start index is inclusive, the end index exclusive. Null array input produces null output.
array
- the arraystartIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in an empty array.endIndexExclusive
- elements up to endIndex-1 are present in the returned subarray.
Undervalue (< startIndex) produces empty array, overvalue (>array.length) is
demoted to array length.Arrays.copyOfRange(int[], int, int)
public static short[] subarray(short[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new short
array containing the elements between the start and end indices.
The start index is inclusive, the end index exclusive. Null array input produces null output.
array
- the arraystartIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in an empty array.endIndexExclusive
- elements up to endIndex-1 are present in the returned subarray.
Undervalue (< startIndex) produces empty array, overvalue (>array.length) is
demoted to array length.Arrays.copyOfRange(short[], int, int)
public static char[] subarray(char[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new char
array containing the elements between the start and end indices.
The start index is inclusive, the end index exclusive. Null array input produces null output.
array
- the arraystartIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in an empty array.endIndexExclusive
- elements up to endIndex-1 are present in the returned subarray.
Undervalue (< startIndex) produces empty array, overvalue (>array.length) is
demoted to array length.Arrays.copyOfRange(char[], int, int)
public static byte[] subarray(byte[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new byte
array containing the elements between the start and end indices.
The start index is inclusive, the end index exclusive. Null array input produces null output.
array
- the arraystartIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in an empty array.endIndexExclusive
- elements up to endIndex-1 are present in the returned subarray.
Undervalue (< startIndex) produces empty array, overvalue (>array.length) is
demoted to array length.Arrays.copyOfRange(byte[], int, int)
public static double[] subarray(double[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new double
array containing the elements between the start and end indices.
The start index is inclusive, the end index exclusive. Null array input produces null output.
array
- the arraystartIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in an empty array.endIndexExclusive
- elements up to endIndex-1 are present in the returned subarray.
Undervalue (< startIndex) produces empty array, overvalue (>array.length) is
demoted to array length.Arrays.copyOfRange(double[], int, int)
public static float[] subarray(float[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new float
array containing the elements between the start and end indices.
The start index is inclusive, the end index exclusive. Null array input produces null output.
array
- the arraystartIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in an empty array.endIndexExclusive
- elements up to endIndex-1 are present in the returned subarray.
Undervalue (< startIndex) produces empty array, overvalue (>array.length) is
demoted to array length.Arrays.copyOfRange(float[], int, int)
public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new boolean
array containing the elements between the start and end indices.
The start index is inclusive, the end index exclusive. Null array input produces null output.
array
- the arraystartIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in an empty array.endIndexExclusive
- elements up to endIndex-1 are present in the returned subarray.
Undervalue (< startIndex) produces empty array, overvalue (>array.length) is
demoted to array length.Arrays.copyOfRange(boolean[], int, int)
public 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 matchesIllegalArgumentException
- 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 for a null
input array.
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 for a null
input array.
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 for a null
input array.
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 for a null
input array.
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 for a null
input array.
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 for a null
input array.
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 for a null
input array.
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 for a null
input array.
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 for a null
input array.
array
- the array to reverse, may be null
public static void reverse(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static void reverse(byte[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static void reverse(char[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static void reverse(double[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static void reverse(float[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static void reverse(int[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static void reverse(long[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static void reverse(Object[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static void reverse(short[] array, int startIndexInclusive, int endIndexExclusive)
Reverses the order of the given array in the given range.
This method does nothing for a null
input array.
array
- the array to reverse, may be null
startIndexInclusive
- the starting index. Undervalue (<0) is promoted to 0, overvalue
(>array.length) results in no change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Undervalue (<
start index) results in no change. Overvalue (>array.length) is demoted to array
length.public static int indexOf(long[] array, long valueToFind)
Finds the index of the given value 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
valueToFind
- the value to findINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(long[] array, long valueToFind, int startIndex)
Finds the index of the given value 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
valueToFind
- the value to findstartIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(long[] array, long valueToFind)
Finds the last index of the given value within the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to findINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(long[] array, long valueToFind, int startIndex)
Finds the last index of the given value in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 fromINDEX_NOT_FOUND
(-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 findtrue
if the array contains the objectpublic static int indexOf(int[] array, int valueToFind)
Finds the index of the given value 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
valueToFind
- the value to findINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(int[] array, int valueToFind, int startIndex)
Finds the index of the given value 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
valueToFind
- the value to findstartIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(int[] array, int valueToFind)
Finds the last index of the given value within the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to findINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(int[] array, int valueToFind, int startIndex)
Finds the last index of the given value in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 fromINDEX_NOT_FOUND
(-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 findtrue
if the array contains the objectpublic static int indexOf(short[] array, short valueToFind)
Finds the index of the given value 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
valueToFind
- the value to findINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(short[] array, short valueToFind, int startIndex)
Finds the index of the given value 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
valueToFind
- the value to findstartIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(short[] array, short valueToFind)
Finds the last index of the given value within the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to findINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(short[] array, short valueToFind, int startIndex)
Finds the last index of the given value in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 fromINDEX_NOT_FOUND
(-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 findtrue
if the array contains the objectpublic static int indexOf(char[] array, char valueToFind)
Finds the index of the given value 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
valueToFind
- the value to findINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(char[] array, char valueToFind, int startIndex)
Finds the index of the given value 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
valueToFind
- the value to findstartIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(char[] array, char valueToFind)
Finds the last index of the given value within the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to findINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(char[] array, char valueToFind, int startIndex)
Finds the last index of the given value in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 fromINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static boolean contains(char[] array, char 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 findtrue
if the array contains the objectpublic static int indexOf(byte[] array, byte valueToFind)
Finds the index of the given value 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
valueToFind
- the value to findINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(byte[] array, byte valueToFind, int startIndex)
Finds the index of the given value 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
valueToFind
- the value to findstartIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(byte[] array, byte valueToFind)
Finds the last index of the given value within the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to findINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(byte[] array, byte valueToFind, int startIndex)
Finds the last index of the given value in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 fromINDEX_NOT_FOUND
(-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 findtrue
if the array contains the objectpublic static int indexOf(double[] array, double valueToFind)
Finds the index of the given value 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
valueToFind
- the value to findINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(double[] array, double valueToFind, double tolerance)
Finds 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 INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to search through for the object, may be null
valueToFind
- the value to findtolerance
- tolerance of the searchINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(double[] array, double valueToFind, int startIndex)
Finds the index of the given value 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
valueToFind
- the value to findstartIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(double[] array, double valueToFind, int startIndex, double tolerance)
Finds 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 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
valueToFind
- the value to findstartIndex
- the index to start searching attolerance
- tolerance of the searchINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(double[] array, double valueToFind)
Finds the last index of the given value within the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to findINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(double[] array, double valueToFind, double tolerance)
Finds 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 INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to search through for the object, may be null
valueToFind
- the value to findtolerance
- tolerance of the searchINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(double[] array, double valueToFind, int startIndex)
Finds the last index of the given value in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 fromINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(double[] array, double valueToFind, int startIndex, double tolerance)
Finds 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 INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 amountINDEX_NOT_FOUND
(-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 findtrue
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 searchpublic static int indexOf(float[] array, float valueToFind)
Finds the index of the given value 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
valueToFind
- the value to findINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(float[] array, float valueToFind, int startIndex)
Finds the index of the given value 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
valueToFind
- the value to findstartIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(float[] array, float valueToFind)
Finds the last index of the given value within the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to findINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(float[] array, float valueToFind, int startIndex)
Finds the last index of the given value in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 fromINDEX_NOT_FOUND
(-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 findtrue
if the array contains the objectpublic static int indexOf(boolean[] array, boolean valueToFind)
Finds the index of the given value 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
valueToFind
- the value to findINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int indexOf(boolean[] array, boolean valueToFind, int startIndex)
Finds the index of the given value 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
valueToFind
- the value to findstartIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not
found or null
array inputpublic static int lastIndexOf(boolean[] array, boolean valueToFind)
Finds the last index of the given value within the array.
This method returns INDEX_NOT_FOUND
(-1
) if null
array input.
array
- the array to travers backwords looking for the object, may be null
valueToFind
- the object to findINDEX_NOT_FOUND
(-1
) if
not found or null
array inputpublic static int lastIndexOf(boolean[] array, boolean valueToFind, int startIndex)
Finds the last index of the given value in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex will return INDEX_NOT_FOUND
(-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 fromINDEX_NOT_FOUND
(-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 findtrue
if the array contains the objectpublic static char[] toPrimitive(Character[] array)
Converts an array of object Characters to primitives.
This method returns null
for a null
input array.
array
- a Character
array, may be null
char
array, null
if null array inputNullPointerException
- if array content is null
public static char[] toPrimitive(Character[] array, char valueForNull)
Converts an array of object Character to primitives handling null
.
This method returns null
for a null
input array.
array
- a Character
array, may be null
valueForNull
- the value to insert if null
foundchar
array, null
if null array inputpublic static Character[] toObject(char[] array)
Converts an array of primitive chars to objects.
This method returns null
for a null
input array.
array
- a char
arrayCharacter
array, null
if null array inputpublic static long[] toPrimitive(Long[] array)
Converts an array of object Longs to primitives.
This method returns null
for a null
input array.
array
- a Long
array, may be null
long
array, null
if null array inputNullPointerException
- 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
for a null
input array.
array
- a Long
array, may be null
valueForNull
- the value to insert if null
foundlong
array, null
if null array inputpublic static Long[] toObject(long[] array)
Converts an array of primitive longs to objects.
This method returns null
for a null
input array.
array
- a long
arrayLong
array, null
if null array inputpublic static int[] toPrimitive(Integer[] array)
Converts an array of object Integers to primitives.
This method returns null
for a null
input array.
array
- a Integer
array, may be null
int
array, null
if null array inputNullPointerException
- 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
for a null
input array.
array
- a Integer
array, may be null
valueForNull
- the value to insert if null
foundint
array, null
if null array inputpublic static Integer[] toObject(int[] array)
Converts an array of primitive ints to objects.
This method returns null
for a null
input array.
array
- an int
arrayInteger
array, null
if null array inputpublic static short[] toPrimitive(Short[] array)
Converts an array of object Shorts to primitives.
This method returns null
for a null
input array.
array
- a Short
array, may be null
byte
array, null
if null array inputNullPointerException
- 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
for a null
input array.
array
- a Short
array, may be null
valueForNull
- the value to insert if null
foundbyte
array, null
if null array inputpublic static Short[] toObject(short[] array)
Converts an array of primitive shorts to objects.
This method returns null
for a null
input array.
array
- a short
arrayShort
array, null
if null array inputpublic static byte[] toPrimitive(Byte[] array)
Converts an array of object Bytes to primitives.
This method returns null
for a null
input array.
array
- a Byte
array, may be null
byte
array, null
if null array inputNullPointerException
- 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
for a null
input array.
array
- a Byte
array, may be null
valueForNull
- the value to insert if null
foundbyte
array, null
if null array inputpublic static Byte[] toObject(byte[] array)
Converts an array of primitive bytes to objects.
This method returns null
for a null
input array.
array
- a byte
arrayByte
array, null
if null array inputpublic static double[] toPrimitive(Double[] array)
Converts an array of object Doubles to primitives.
This method returns null
for a null
input array.
array
- a Double
array, may be null
double
array, null
if null array inputNullPointerException
- 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
for a null
input array.
array
- a Double
array, may be null
valueForNull
- the value to insert if null
founddouble
array, null
if null array inputpublic static Double[] toObject(double[] array)
Converts an array of primitive doubles to objects.
This method returns null
for a null
input array.
array
- a double
arrayDouble
array, null
if null array inputpublic static float[] toPrimitive(Float[] array)
Converts an array of object Floats to primitives.
This method returns null
for a null
input array.
array
- a Float
array, may be null
float
array, null
if null array inputNullPointerException
- 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
for a null
input array.
array
- a Float
array, may be null
valueForNull
- the value to insert if null
foundfloat
array, null
if null array inputpublic static Float[] toObject(float[] array)
Converts an array of primitive floats to objects.
This method returns null
for a null
input array.
array
- a float
arrayFloat
array, null
if null array inputpublic static boolean[] toPrimitive(Boolean[] array)
Converts an array of object Booleans to primitives.
This method returns null
for a null
input array.
array
- a Boolean
array, may be null
boolean
array, null
if null array inputNullPointerException
- 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
for a null
input array.
array
- a Boolean
array, may be null
valueForNull
- the value to insert if null
foundboolean
array, null
if null array inputpublic static Boolean[] toObject(boolean[] array)
Converts an array of primitive booleans to objects.
This method returns null
for a null
input array.
array
- a boolean
arrayBoolean
array, null
if null array inputpublic static boolean isEmpty(Object[] array)
Checks if an array of Objects is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static boolean isEmpty(long[] array)
Checks if an array of primitive longs is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static boolean isEmpty(int[] array)
Checks if an array of primitive ints is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static boolean isEmpty(short[] array)
Checks if an array of primitive shorts is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static boolean isEmpty(char[] array)
Checks if an array of primitive chars is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static boolean isEmpty(byte[] array)
Checks if an array of primitive bytes is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static boolean isEmpty(double[] array)
Checks if an array of primitive doubles is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static boolean isEmpty(float[] array)
Checks if an array of primitive floats is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static boolean isEmpty(boolean[] array)
Checks if an array of primitive booleans is empty or null
.
array
- the array to testtrue
if the array is empty or null
public static <T> boolean isNotEmpty(T[] array)
Checks if an array of Objects is not empty or not null
.
T
- the component type of the arrayarray
- the array to testtrue
if the array is not empty or not null
public static boolean isNotEmpty(long[] array)
Checks if an array of primitive longs is not empty or not null
.
array
- the array to testtrue
if the array is not empty or not null
public static boolean isNotEmpty(int[] array)
Checks if an array of primitive ints is not empty or not null
.
array
- the array to testtrue
if the array is not empty or not null
public static boolean isNotEmpty(short[] array)
Checks if an array of primitive shorts is not empty or not null
.
array
- the array to testtrue
if the array is not empty or not null
public static boolean isNotEmpty(char[] array)
Checks if an array of primitive chars is not empty or not null
.
array
- the array to testtrue
if the array is not empty or not null
public static boolean isNotEmpty(byte[] array)
Checks if an array of primitive bytes is not empty or not null
.
array
- the array to testtrue
if the array is not empty or not null
public static boolean isNotEmpty(double[] array)
Checks if an array of primitive doubles is not empty or not null
.
array
- the array to testtrue
if the array is not empty or not null
public static boolean isNotEmpty(float[] array)
Checks if an array of primitive floats is not empty or not null
.
array
- the array to testtrue
if the array is not empty or not null
public static boolean isNotEmpty(boolean[] array)
Checks if an array of primitive booleans is not empty or not null
.
array
- the array to testtrue
if the array is not empty or not null
Copyright © 2014. All rights reserved.