public class ArrayUtils
extends java.lang.Object
Operations on arrays, primitive arrays (like int[]
) and
primitive wrapper arrays (like Integer[]
).
This class tries to handle null
input gracefully.
An exception will not be thrown for a null
array input. However, an Object array that contains a null
element may throw an exception. Each method documents its behaviour.
#ThreadSafe#
Modifier and Type | Field and Description |
---|---|
static boolean[] |
EMPTY_BOOLEAN_ARRAY
An empty immutable
boolean array. |
static java.lang.Boolean[] |
EMPTY_BOOLEAN_OBJECT_ARRAY
An empty immutable
Boolean array. |
static byte[] |
EMPTY_BYTE_ARRAY
An empty immutable
byte array. |
static java.lang.Byte[] |
EMPTY_BYTE_OBJECT_ARRAY
An empty immutable
Byte array. |
static char[] |
EMPTY_CHAR_ARRAY
An empty immutable
char array. |
static java.lang.Character[] |
EMPTY_CHARACTER_OBJECT_ARRAY
An empty immutable
Character array. |
static java.lang.Class<?>[] |
EMPTY_CLASS_ARRAY
An empty immutable
Class array. |
static double[] |
EMPTY_DOUBLE_ARRAY
An empty immutable
double array. |
static java.lang.Double[] |
EMPTY_DOUBLE_OBJECT_ARRAY
An empty immutable
Double array. |
static float[] |
EMPTY_FLOAT_ARRAY
An empty immutable
float array. |
static java.lang.Float[] |
EMPTY_FLOAT_OBJECT_ARRAY
An empty immutable
Float array. |
static int[] |
EMPTY_INT_ARRAY
An empty immutable
int array. |
static java.lang.Integer[] |
EMPTY_INTEGER_OBJECT_ARRAY
An empty immutable
Integer array. |
static long[] |
EMPTY_LONG_ARRAY
An empty immutable
long array. |
static java.lang.Long[] |
EMPTY_LONG_OBJECT_ARRAY
An empty immutable
Long array. |
static java.lang.Object[] |
EMPTY_OBJECT_ARRAY
An empty immutable
Object array. |
static short[] |
EMPTY_SHORT_ARRAY
An empty immutable
short array. |
static java.lang.Short[] |
EMPTY_SHORT_OBJECT_ARRAY
An empty immutable
Short array. |
static java.lang.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[] |
add(boolean[] array,
boolean element)
Copies the given array and adds the given element at the end of the new array.
|
static boolean[] |
add(boolean[] array,
int index,
boolean element)
Deprecated.
this method has been superseded by
insert(int, boolean[], boolean...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static byte[] |
add(byte[] array,
byte element)
Copies the given array and adds the given element at the end of the new array.
|
static byte[] |
add(byte[] array,
int index,
byte element)
Deprecated.
this method has been superseded by
insert(int, byte[], byte...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static char[] |
add(char[] array,
char element)
Copies the given array and adds the given element at the end of the new array.
|
static char[] |
add(char[] array,
int index,
char element)
Deprecated.
this method has been superseded by
insert(int, char[], char...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static double[] |
add(double[] array,
double element)
Copies the given array and adds the given element at the end of the new array.
|
static double[] |
add(double[] array,
int index,
double element)
Deprecated.
this method has been superseded by
insert(int, double[], double...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static float[] |
add(float[] array,
float element)
Copies the given array and adds the given element at the end of the new array.
|
static float[] |
add(float[] array,
int index,
float element)
Deprecated.
this method has been superseded by
insert(int, float[], float...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static int[] |
add(int[] array,
int element)
Copies the given array and adds the given element at the end of the new array.
|
static int[] |
add(int[] array,
int index,
int element)
Deprecated.
this method has been superseded by
insert(int, int[], int...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static long[] |
add(long[] array,
int index,
long element)
Deprecated.
this method has been superseded by
insert(int, long[], long...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static long[] |
add(long[] array,
long element)
Copies the given array and adds the given element at the end of the new array.
|
static short[] |
add(short[] array,
int index,
short element)
Deprecated.
this method has been superseded by
insert(int, short[], short...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static short[] |
add(short[] array,
short element)
Copies the given array and adds the given element at the end of the new array.
|
static <T> T[] |
add(T[] array,
int index,
T element)
Deprecated.
this method has been superseded by
insert(int, T[], T...) and
may be removed in a future release. Please note the handling of null input arrays differs
in the new method: inserting X into a null array results in null not X . |
static <T> T[] |
add(T[] array,
T element)
Copies the given array and adds the given element at the end of the new array.
|
static boolean[] |
addAll(boolean[] array1,
boolean... array2)
Adds all the elements of the given arrays into a new array.
|
static byte[] |
addAll(byte[] array1,
byte... array2)
Adds all the elements of the given arrays into a new array.
|
static char[] |
addAll(char[] array1,
char... array2)
Adds all the elements of the given arrays into a new array.
|
static double[] |
addAll(double[] array1,
double... array2)
Adds all the elements of the given arrays into a new array.
|
static float[] |
addAll(float[] array1,
float... array2)
Adds all the elements of the given arrays into a new array.
|
static int[] |
addAll(int[] array1,
int... array2)
Adds all the elements of the given arrays into a new array.
|
static long[] |
addAll(long[] array1,
long... array2)
Adds all the elements of the given arrays into a new array.
|
static short[] |
addAll(short[] array1,
short... array2)
Adds all the elements of the given arrays into a new array.
|
static <T> T[] |
addAll(T[] array1,
T... array2)
Adds all the elements of the given arrays into a new array.
|
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 short[] |
clone(short[] array)
Clones an array returning a typecast result and handling
null . |
static <T> T[] |
clone(T[] array)
Shallow 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(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(java.lang.Object[] array,
java.lang.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 |
getLength(java.lang.Object array)
Returns the length of the specified array.
|
static int |
hashCode(java.lang.Object array)
Get a hash code for an array handling multi-dimensional arrays correctly.
|
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(java.lang.Object[] array,
java.lang.Object objectToFind)
Finds the index of the given object in the array.
|
static int |
indexOf(java.lang.Object[] array,
java.lang.Object objectToFind,
int startIndex)
Finds the index of the given object in the array starting at the given index.
|
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[] |
insert(int index,
boolean[] array,
boolean... values)
Inserts elements into an array at the given index (starting from zero).
|
static byte[] |
insert(int index,
byte[] array,
byte... values)
Inserts elements into an array at the given index (starting from zero).
|
static char[] |
insert(int index,
char[] array,
char... values)
Inserts elements into an array at the given index (starting from zero).
|
static double[] |
insert(int index,
double[] array,
double... values)
Inserts elements into an array at the given index (starting from zero).
|
static float[] |
insert(int index,
float[] array,
float... values)
Inserts elements into an array at the given index (starting from zero).
|
static int[] |
insert(int index,
int[] array,
int... values)
Inserts elements into an array at the given index (starting from zero).
|
static long[] |
insert(int index,
long[] array,
long... values)
Inserts elements into an array at the given index (starting from zero).
|
static short[] |
insert(int index,
short[] array,
short... values)
Inserts elements into an array at the given index (starting from zero).
|
static <T> T[] |
insert(int index,
T[] array,
T... values)
Inserts elements into an array at the given index (starting from zero).
|
static <T> boolean |
isArrayIndexValid(T[] array,
int index)
Returns whether a given array can safely be accessed 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(java.lang.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 |
isEquals(java.lang.Object array1,
java.lang.Object array2)
Deprecated.
this method has been replaced by
java.util.Objects.deepEquals(Object, Object) and will be
removed from future releases. |
static boolean |
isNotEmpty(boolean[] array)
Checks if an array of primitive booleans is not empty and not
null . |
static boolean |
isNotEmpty(byte[] array)
Checks if an array of primitive bytes is not empty and not
null . |
static boolean |
isNotEmpty(char[] array)
Checks if an array of primitive chars is not empty and not
null . |
static boolean |
isNotEmpty(double[] array)
Checks if an array of primitive doubles is not empty and not
null . |
static boolean |
isNotEmpty(float[] array)
Checks if an array of primitive floats is not empty and not
null . |
static boolean |
isNotEmpty(int[] array)
Checks if an array of primitive ints is not empty and not
null . |
static boolean |
isNotEmpty(long[] array)
Checks if an array of primitive longs is not empty and not
null . |
static boolean |
isNotEmpty(short[] array)
Checks if an array of primitive shorts is not empty and not
null . |
static <T> boolean |
isNotEmpty(T[] array)
Checks if an array of Objects is not empty and 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(java.lang.Object[] array1,
java.lang.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(java.lang.Object array1,
java.lang.Object array2)
Checks whether two arrays are the same type taking into account
multi-dimensional arrays.
|
static boolean |
isSorted(boolean[] array)
This method checks whether the provided array is sorted according to natural ordering
(
false before true ). |
static boolean |
isSorted(byte[] array)
This method checks whether the provided array is sorted according to natural ordering.
|
static boolean |
isSorted(char[] array)
This method checks whether the provided array is sorted according to natural ordering.
|
static boolean |
isSorted(double[] array)
This method checks whether the provided array is sorted according to natural ordering.
|
static boolean |
isSorted(float[] array)
This method checks whether the provided array is sorted according to natural ordering.
|
static boolean |
isSorted(int[] array)
This method checks whether the provided array is sorted according to natural ordering.
|
static boolean |
isSorted(long[] array)
This method checks whether the provided array is sorted according to natural ordering.
|
static boolean |
isSorted(short[] array)
This method checks whether the provided array is sorted according to natural ordering.
|
static <T extends java.lang.Comparable<? super T>> |
isSorted(T[] array)
This method checks whether the provided array is sorted according to the class's
compareTo method. |
static <T> boolean |
isSorted(T[] array,
java.util.Comparator<T> comparator)
This method checks whether the provided array is sorted according to the provided
Comparator . |
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(java.lang.Object[] array,
java.lang.Object objectToFind)
Finds the last index of the given object within the array.
|
static int |
lastIndexOf(java.lang.Object[] array,
java.lang.Object objectToFind,
int startIndex)
Finds the last index of the given object 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 java.lang.Boolean[] |
nullToEmpty(java.lang.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 java.lang.Byte[] |
nullToEmpty(java.lang.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 java.lang.Character[] |
nullToEmpty(java.lang.Character[] array)
Defensive programming technique to change a
null
reference to an empty one. |
static java.lang.Class<?>[] |
nullToEmpty(java.lang.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 java.lang.Double[] |
nullToEmpty(java.lang.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 java.lang.Float[] |
nullToEmpty(java.lang.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 java.lang.Integer[] |
nullToEmpty(java.lang.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 java.lang.Long[] |
nullToEmpty(java.lang.Long[] array)
Defensive programming technique to change a
null
reference to an empty one. |
static java.lang.Object[] |
nullToEmpty(java.lang.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 java.lang.Short[] |
nullToEmpty(java.lang.Short[] array)
Defensive programming technique to change a
null
reference to an empty one. |
static java.lang.String[] |
nullToEmpty(java.lang.String[] array)
Defensive programming technique to change a
null
reference to an empty one. |
static <T> T[] |
nullToEmpty(T[] array,
java.lang.Class<T[]> type)
Defensive programming technique to change a
null
reference to an empty one. |
static boolean[] |
remove(boolean[] array,
int index)
Removes the element at the specified position from the specified array.
|
static byte[] |
remove(byte[] array,
int index)
Removes the element at the specified position from the specified array.
|
static char[] |
remove(char[] array,
int index)
Removes the element at the specified position from the specified array.
|
static double[] |
remove(double[] array,
int index)
Removes the element at the specified position from the specified array.
|
static float[] |
remove(float[] array,
int index)
Removes the element at the specified position from the specified array.
|
static int[] |
remove(int[] array,
int index)
Removes the element at the specified position from the specified array.
|
static long[] |
remove(long[] array,
int index)
Removes the element at the specified position from the specified array.
|
static short[] |
remove(short[] array,
int index)
Removes the element at the specified position from the specified array.
|
static <T> T[] |
remove(T[] array,
int index)
Removes the element at the specified position from the specified array.
|
static boolean[] |
removeAll(boolean[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static byte[] |
removeAll(byte[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static char[] |
removeAll(char[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static double[] |
removeAll(double[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static float[] |
removeAll(float[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static int[] |
removeAll(int[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static long[] |
removeAll(long[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static short[] |
removeAll(short[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static <T> T[] |
removeAll(T[] array,
int... indices)
Removes the elements at the specified positions from the specified array.
|
static boolean[] |
removeAllOccurences(boolean[] array,
boolean element)
Removes the occurrences of the specified element from the specified boolean array.
|
static byte[] |
removeAllOccurences(byte[] array,
byte element)
Removes the occurrences of the specified element from the specified byte array.
|
static char[] |
removeAllOccurences(char[] array,
char element)
Removes the occurrences of the specified element from the specified char array.
|
static double[] |
removeAllOccurences(double[] array,
double element)
Removes the occurrences of the specified element from the specified double array.
|
static float[] |
removeAllOccurences(float[] array,
float element)
Removes the occurrences of the specified element from the specified float array.
|
static int[] |
removeAllOccurences(int[] array,
int element)
Removes the occurrences of the specified element from the specified int array.
|
static long[] |
removeAllOccurences(long[] array,
long element)
Removes the occurrences of the specified element from the specified long array.
|
static short[] |
removeAllOccurences(short[] array,
short element)
Removes the occurrences of the specified element from the specified short array.
|
static <T> T[] |
removeAllOccurences(T[] array,
T element)
Removes the occurrences of the specified element from the specified array.
|
static boolean[] |
removeElement(boolean[] array,
boolean element)
Removes the first occurrence of the specified element from the
specified array.
|
static byte[] |
removeElement(byte[] array,
byte element)
Removes the first occurrence of the specified element from the
specified array.
|
static char[] |
removeElement(char[] array,
char element)
Removes the first occurrence of the specified element from the
specified array.
|
static double[] |
removeElement(double[] array,
double element)
Removes the first occurrence of the specified element from the
specified array.
|
static float[] |
removeElement(float[] array,
float element)
Removes the first occurrence of the specified element from the
specified array.
|
static int[] |
removeElement(int[] array,
int element)
Removes the first occurrence of the specified element from the
specified array.
|
static long[] |
removeElement(long[] array,
long element)
Removes the first occurrence of the specified element from the
specified array.
|
static short[] |
removeElement(short[] array,
short element)
Removes the first occurrence of the specified element from the
specified array.
|
static <T> T[] |
removeElement(T[] array,
java.lang.Object element)
Removes the first occurrence of the specified element from the
specified array.
|
static boolean[] |
removeElements(boolean[] array,
boolean... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
static byte[] |
removeElements(byte[] array,
byte... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
static char[] |
removeElements(char[] array,
char... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
static double[] |
removeElements(double[] array,
double... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
static float[] |
removeElements(float[] array,
float... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
static int[] |
removeElements(int[] array,
int... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
static long[] |
removeElements(long[] array,
long... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
static short[] |
removeElements(short[] array,
short... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
static <T> T[] |
removeElements(T[] array,
T... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
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(java.lang.Object[] array)
Reverses the order of the given array.
|
static void |
reverse(java.lang.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 void |
shift(boolean[] array,
int offset)
Shifts the order of the given boolean array.
|
static void |
shift(boolean[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given boolean array.
|
static void |
shift(byte[] array,
int offset)
Shifts the order of the given byte array.
|
static void |
shift(byte[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given byte array.
|
static void |
shift(char[] array,
int offset)
Shifts the order of the given char array.
|
static void |
shift(char[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given char array.
|
static void |
shift(double[] array,
int offset)
Shifts the order of the given double array.
|
static void |
shift(double[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given double array.
|
static void |
shift(float[] array,
int offset)
Shifts the order of the given float array.
|
static void |
shift(float[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given float array.
|
static void |
shift(int[] array,
int offset)
Shifts the order of the given int array.
|
static void |
shift(int[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given int array.
|
static void |
shift(long[] array,
int offset)
Shifts the order of the given long array.
|
static void |
shift(long[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given long array.
|
static void |
shift(java.lang.Object[] array,
int offset)
Shifts the order of the given array.
|
static void |
shift(java.lang.Object[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given array.
|
static void |
shift(short[] array,
int offset)
Shifts the order of the given short array.
|
static void |
shift(short[] array,
int startIndexInclusive,
int endIndexExclusive,
int offset)
Shifts the order of a series of elements in the given short array.
|
static void |
shuffle(boolean[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(boolean[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(byte[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(byte[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(char[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(char[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(double[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(double[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(float[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(float[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(int[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(int[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(long[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(long[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(java.lang.Object[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(java.lang.Object[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(short[] array)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
static void |
shuffle(short[] array,
java.util.Random random)
Randomly permutes the elements of the specified array using the Fisher-Yates algorithm.
|
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 <T> T[] |
subarray(T[] array,
int startIndexInclusive,
int endIndexExclusive)
Produces a new array containing the elements between
the start and end indices.
|
static void |
swap(boolean[] array,
int offset1,
int offset2)
Swaps two elements in the given boolean array.
|
static void |
swap(boolean[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given boolean array.
|
static void |
swap(byte[] array,
int offset1,
int offset2)
Swaps two elements in the given byte array.
|
static void |
swap(byte[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given byte array.
|
static void |
swap(char[] array,
int offset1,
int offset2)
Swaps two elements in the given char array.
|
static void |
swap(char[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given char array.
|
static void |
swap(double[] array,
int offset1,
int offset2)
Swaps two elements in the given double array.
|
static void |
swap(double[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given double array.
|
static void |
swap(float[] array,
int offset1,
int offset2)
Swaps two elements in the given float array.
|
static void |
swap(float[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given float array.
|
static void |
swap(int[] array,
int offset1,
int offset2)
Swaps two elements in the given int array.
|
static void |
swap(int[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given int array.
|
static void |
swap(long[] array,
int offset1,
int offset2)
Swaps two elements in the given long array.
|
static void |
swap(long[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given long array.
|
static void |
swap(java.lang.Object[] array,
int offset1,
int offset2)
Swaps two elements in the given array.
|
static void |
swap(java.lang.Object[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given array.
|
static void |
swap(short[] array,
int offset1,
int offset2)
Swaps two elements in the given short array.
|
static void |
swap(short[] array,
int offset1,
int offset2,
int len)
Swaps a series of elements in the given short array.
|
static <T> T[] |
toArray(T... items)
Create a type-safe generic array.
|
static java.util.Map<java.lang.Object,java.lang.Object> |
toMap(java.lang.Object[] array)
Converts the given array into a
Map . |
static java.lang.Boolean[] |
toObject(boolean[] array)
Converts an array of primitive booleans to objects.
|
static java.lang.Byte[] |
toObject(byte[] array)
Converts an array of primitive bytes to objects.
|
static java.lang.Character[] |
toObject(char[] array)
Converts an array of primitive chars to objects.
|
static java.lang.Double[] |
toObject(double[] array)
Converts an array of primitive doubles to objects.
|
static java.lang.Float[] |
toObject(float[] array)
Converts an array of primitive floats to objects.
|
static java.lang.Integer[] |
toObject(int[] array)
Converts an array of primitive ints to objects.
|
static java.lang.Long[] |
toObject(long[] array)
Converts an array of primitive longs to objects.
|
static java.lang.Short[] |
toObject(short[] array)
Converts an array of primitive shorts to objects.
|
static boolean[] |
toPrimitive(java.lang.Boolean[] array)
Converts an array of object Booleans to primitives.
|
static boolean[] |
toPrimitive(java.lang.Boolean[] array,
boolean valueForNull)
Converts an array of object Booleans to primitives handling
null . |
static byte[] |
toPrimitive(java.lang.Byte[] array)
Converts an array of object Bytes to primitives.
|
static byte[] |
toPrimitive(java.lang.Byte[] array,
byte valueForNull)
Converts an array of object Bytes to primitives handling
null . |
static char[] |
toPrimitive(java.lang.Character[] array)
Converts an array of object Characters to primitives.
|
static char[] |
toPrimitive(java.lang.Character[] array,
char valueForNull)
Converts an array of object Character to primitives handling
null . |
static double[] |
toPrimitive(java.lang.Double[] array)
Converts an array of object Doubles to primitives.
|
static double[] |
toPrimitive(java.lang.Double[] array,
double valueForNull)
Converts an array of object Doubles to primitives handling
null . |
static float[] |
toPrimitive(java.lang.Float[] array)
Converts an array of object Floats to primitives.
|
static float[] |
toPrimitive(java.lang.Float[] array,
float valueForNull)
Converts an array of object Floats to primitives handling
null . |
static int[] |
toPrimitive(java.lang.Integer[] array)
Converts an array of object Integers to primitives.
|
static int[] |
toPrimitive(java.lang.Integer[] array,
int valueForNull)
Converts an array of object Integer to primitives handling
null . |
static long[] |
toPrimitive(java.lang.Long[] array)
Converts an array of object Longs to primitives.
|
static long[] |
toPrimitive(java.lang.Long[] array,
long valueForNull)
Converts an array of object Long to primitives handling
null . |
static java.lang.Object |
toPrimitive(java.lang.Object array)
Create an array of primitive type from an array of wrapper types.
|
static short[] |
toPrimitive(java.lang.Short[] array)
Converts an array of object Shorts to primitives.
|
static short[] |
toPrimitive(java.lang.Short[] array,
short valueForNull)
Converts an array of object Short to primitives handling
null . |
static java.lang.String |
toString(java.lang.Object array)
Outputs an array as a String, treating
null as an empty array. |
static java.lang.String |
toString(java.lang.Object array,
java.lang.String stringIfNull)
Outputs an array as a String handling
null s. |
static java.lang.String[] |
toStringArray(java.lang.Object[] array)
Returns an array containing the string representation of each element in the argument array.
|
static java.lang.String[] |
toStringArray(java.lang.Object[] array,
java.lang.String valueForNullElements)
Returns an array containing the string representation of each element in the argument
array handling
null elements. |
public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
Object
array.public static final java.lang.Class<?>[] EMPTY_CLASS_ARRAY
Class
array.public static final java.lang.String[] EMPTY_STRING_ARRAY
String
array.public static final long[] EMPTY_LONG_ARRAY
long
array.public static final java.lang.Long[] EMPTY_LONG_OBJECT_ARRAY
Long
array.public static final int[] EMPTY_INT_ARRAY
int
array.public static final java.lang.Integer[] EMPTY_INTEGER_OBJECT_ARRAY
Integer
array.public static final short[] EMPTY_SHORT_ARRAY
short
array.public static final java.lang.Short[] EMPTY_SHORT_OBJECT_ARRAY
Short
array.public static final byte[] EMPTY_BYTE_ARRAY
byte
array.public static final java.lang.Byte[] EMPTY_BYTE_OBJECT_ARRAY
Byte
array.public static final double[] EMPTY_DOUBLE_ARRAY
double
array.public static final java.lang.Double[] EMPTY_DOUBLE_OBJECT_ARRAY
Double
array.public static final float[] EMPTY_FLOAT_ARRAY
float
array.public static final java.lang.Float[] EMPTY_FLOAT_OBJECT_ARRAY
Float
array.public static final boolean[] EMPTY_BOOLEAN_ARRAY
boolean
array.public static final java.lang.Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY
Boolean
array.public static final char[] EMPTY_CHAR_ARRAY
char
array.public static final java.lang.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 java.lang.String toString(java.lang.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 java.lang.String toString(java.lang.Object array, java.lang.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(java.lang.Object array)
Get a hash code 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 hash code for, null
returns zero@Deprecated public static boolean isEquals(java.lang.Object array1, java.lang.Object array2)
java.util.Objects.deepEquals(Object, Object)
and will be
removed from future releases.Compares two arrays, using equals(), handling multi-dimensional arrays correctly.
Multi-dimensional primitive arrays are also handled correctly by this method.
array1
- the left hand array to compare, may be null
array2
- the right hand array to compare, may be null
true
if the arrays are equalpublic static java.util.Map<java.lang.Object,java.lang.Object> toMap(java.lang.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 = ArrayUtils.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 arrayjava.lang.IllegalArgumentException
- if one element of this Array is
itself an Array containing less then two elementsjava.lang.IllegalArgumentException
- if the array contains elements other
than Map.Entry
and an Arraypublic static <T> T[] toArray(T... items)
Create a type-safe generic array.
The Java language does not allow an array to be created from a generic type:
public static <T> T[] createAnArray(int size) { return new T[size]; // compiler error here } public static <T> T[] createAnArray(int size) { return (T[]) new Object[size]; // ClassCastException at runtime }
Therefore new arrays of generic types can be created with this method. For example, an array of Strings can be created:
String[] array = ArrayUtils.toArray("1", "2"); String[] emptyArray = ArrayUtils.<String>toArray();
The method is typically used in scenarios, where the caller itself uses generic types that have to be combined into an array.
Note, this method makes only sense to provide arguments of the same type so that the
compiler can deduce the type of the array itself. While it is possible to select the
type explicitly like in
Number[] array = ArrayUtils.<Number>toArray(Integer.valueOf(42), Double.valueOf(Math.PI))
,
there is no real advantage when compared to
new Number[] {Integer.valueOf(42), Double.valueOf(Math.PI)}
.
T
- the array's element typeitems
- the varargs array items, null allowedpublic static <T> T[] clone(T[] array)
Shallow clones an array returning a typecast result and handling
null
.
The objects in the array are not cloned, thus there is no special handling for multi-dimensional arrays.
This method returns null
for a null
input array.
T
- the component type of the arrayarray
- 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
for a null
input array.
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
for a null
input array.
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
for a null
input array.
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
for a null
input array.
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
for a null
input array.
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
for a null
input array.
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
for a null
input array.
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
for a null
input array.
array
- the array to clone, may be null
null
if null
inputpublic static <T> T[] nullToEmpty(T[] array, java.lang.Class<T[]> type)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
T
- the class typearray
- the array to check for null
or emptytype
- the class representation of the desired arraypublic static
empty array if null
java.lang.IllegalArgumentException
- if the type argument is nullpublic static java.lang.Object[] nullToEmpty(java.lang.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 java.lang.Class<?>[] nullToEmpty(java.lang.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 java.lang.String[] nullToEmpty(java.lang.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 java.lang.Long[] nullToEmpty(java.lang.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 java.lang.Integer[] nullToEmpty(java.lang.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 java.lang.Short[] nullToEmpty(java.lang.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 java.lang.Character[] nullToEmpty(java.lang.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 java.lang.Byte[] nullToEmpty(java.lang.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 java.lang.Double[] nullToEmpty(java.lang.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 java.lang.Float[] nullToEmpty(java.lang.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 java.lang.Boolean[] nullToEmpty(java.lang.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 <T> T[] subarray(T[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new 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.
The component type of the subarray is always the same as
that of the input array. Thus, if the input is an array of type
Date
, the following usage is envisaged:
Date[] someDates = (Date[]) ArrayUtils.subarray(allDates, 2, 5);
T
- the component type of the arrayarray
- 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(Object[], int, int)
public 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(java.lang.Object[] array1, java.lang.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 int getLength(java.lang.Object array)
Returns the length of the specified array.
This method can deal with Object
arrays and with primitive arrays.
If the input array is null
, 0
is returned.
ArrayUtils.getLength(null) = 0 ArrayUtils.getLength([]) = 0 ArrayUtils.getLength([null]) = 1 ArrayUtils.getLength([true, false]) = 2 ArrayUtils.getLength([1, 2, 3]) = 3 ArrayUtils.getLength(["a", "b", "c"]) = 3
array
- the array to retrieve the length from, may be null0
if the array is null
java.lang.IllegalArgumentException
- if the object argument is not an array.public static boolean isSameType(java.lang.Object array1, java.lang.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 matchesjava.lang.IllegalArgumentException
- if either array is null
public static void reverse(java.lang.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(java.lang.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. Under value (<0) is promoted to 0, over value (>array.length) results in no
change.endIndexExclusive
- elements up to endIndex-1 are reversed in the array. Under value (< start index) results in no
change. Over value (>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 void swap(java.lang.Object[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(long[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(int[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(short[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(char[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(byte[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(double[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(float[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(boolean[] array, int offset1, int offset2)
There is no special handling for multi-dimensional arrays. This method
does nothing for a null
or empty input array or for overflow indices.
Negative indices are promoted to 0(zero).
array
- the array to swap, may be null
offset1
- the index of the first element to swapoffset2
- the index of the second element to swappublic static void swap(boolean[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void swap(byte[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void swap(char[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void swap(double[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void swap(float[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void swap(int[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void swap(long[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void swap(java.lang.Object[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void swap(short[] array, int offset1, int offset2, int len)
This method does nothing for a null
or empty input array or
for overflow indices. Negative indices are promoted to 0(zero). If any
of the sub-arrays to swap falls outside of the given array, then the
swap is stopped at the end of the array and as many as possible elements
are swapped.
array
- the array to swap, may be null
offset1
- the index of the first element in the series to swapoffset2
- the index of the second element in the series to swaplen
- the number of elements to swap starting with the given indicespublic static void shift(java.lang.Object[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(long[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(int[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(short[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(char[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(byte[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(double[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(float[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(boolean[] array, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, may be null
offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(boolean[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(byte[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(char[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(double[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(float[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(int[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(long[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(java.lang.Object[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static void shift(short[] array, int startIndexInclusive, int endIndexExclusive, int offset)
There is no special handling for multi-dimensional arrays. This method
does nothing for null
or empty input arrays.
array
- the array to shift, 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 shifted in the array. Undervalue (< start index) results in no
change. Overvalue (>array.length) is demoted to array length.offset
- The number of positions to rotate the elements. If the offset is larger than the number of elements to
rotate, than the effective offset is modulo the number of elements to rotate.public static int indexOf(java.lang.Object[] array, java.lang.Object objectToFind)
Finds the index of the given object in the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to search through for the object, may be null
objectToFind
- the object to find, may be null
INDEX_NOT_FOUND
(-1
) if not found or null
array inputpublic static int indexOf(java.lang.Object[] array, java.lang.Object objectToFind, int startIndex)
Finds the index of the given object in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex is treated as zero. A startIndex larger than the array
length will return INDEX_NOT_FOUND
(-1
).
array
- the array to search through for the object, may be null
objectToFind
- the object to find, may be null
startIndex
- the index to start searching atINDEX_NOT_FOUND
(-1
) if not found or null
array inputpublic static int lastIndexOf(java.lang.Object[] array, java.lang.Object objectToFind)
Finds the last index of the given object within the array.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
array
- the array to traverse backwards looking for the object, may be null
objectToFind
- the object to find, may be null
INDEX_NOT_FOUND
(-1
) if not found or null
array inputpublic static int lastIndexOf(java.lang.Object[] array, java.lang.Object objectToFind, int startIndex)
Finds the last index of the given object in the array starting at the given index.
This method returns INDEX_NOT_FOUND
(-1
) for a null
input array.
A negative startIndex 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
objectToFind
- the object to find, may be null
startIndex
- the start index to traverse backwards fromINDEX_NOT_FOUND
(-1
) if not found or null
array inputpublic static boolean contains(java.lang.Object[] array, java.lang.Object objectToFind)
Checks if the object is in the given array.
The method returns false
if a null
array is passed in.
array
- the array to search throughobjectToFind
- the object to findtrue
if the array contains the objectpublic 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 traverse backwards 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 traverse 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 traverse backwards 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 traverse 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 traverse backwards 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 traverse 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 traverse backwards 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 traverse 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 traverse backwards 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 traverse 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 traverse backwards 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 traverse 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 traverse 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 traverse backwards 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 traverse 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 traverse backwards 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 traverse 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(java.lang.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 inputjava.lang.NullPointerException
- if array content is null
public static char[] toPrimitive(java.lang.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 java.lang.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(java.lang.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 inputjava.lang.NullPointerException
- if array content is null
public static long[] toPrimitive(java.lang.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 java.lang.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(java.lang.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 inputjava.lang.NullPointerException
- if array content is null
public static int[] toPrimitive(java.lang.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 java.lang.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(java.lang.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 inputjava.lang.NullPointerException
- if array content is null
public static short[] toPrimitive(java.lang.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 java.lang.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(java.lang.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 inputjava.lang.NullPointerException
- if array content is null
public static byte[] toPrimitive(java.lang.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 java.lang.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(java.lang.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 inputjava.lang.NullPointerException
- if array content is null
public static double[] toPrimitive(java.lang.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 java.lang.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(java.lang.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 inputjava.lang.NullPointerException
- if array content is null
public static float[] toPrimitive(java.lang.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 java.lang.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 java.lang.Object toPrimitive(java.lang.Object array)
Create an array of primitive type from an array of wrapper types.
This method returns null
for a null
input array.
array
- an array of wrapper objectpublic static boolean[] toPrimitive(java.lang.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 inputjava.lang.NullPointerException
- if array content is null
public static boolean[] toPrimitive(java.lang.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 java.lang.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(java.lang.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 and not null
.
T
- the component type of the arrayarray
- the array to testtrue
if the array is not empty and not null
public static boolean isNotEmpty(long[] array)
Checks if an array of primitive longs is not empty and not null
.
array
- the array to testtrue
if the array is not empty and not null
public static boolean isNotEmpty(int[] array)
Checks if an array of primitive ints is not empty and not null
.
array
- the array to testtrue
if the array is not empty and not null
public static boolean isNotEmpty(short[] array)
Checks if an array of primitive shorts is not empty and not null
.
array
- the array to testtrue
if the array is not empty and not null
public static boolean isNotEmpty(char[] array)
Checks if an array of primitive chars is not empty and not null
.
array
- the array to testtrue
if the array is not empty and not null
public static boolean isNotEmpty(byte[] array)
Checks if an array of primitive bytes is not empty and not null
.
array
- the array to testtrue
if the array is not empty and not null
public static boolean isNotEmpty(double[] array)
Checks if an array of primitive doubles is not empty and not null
.
array
- the array to testtrue
if the array is not empty and not null
public static boolean isNotEmpty(float[] array)
Checks if an array of primitive floats is not empty and not null
.
array
- the array to testtrue
if the array is not empty and not null
public static boolean isNotEmpty(boolean[] array)
Checks if an array of primitive booleans is not empty and not null
.
array
- the array to testtrue
if the array is not empty and not null
public static <T> T[] addAll(T[] array1, T... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(null, null) = null ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = [] ArrayUtils.addAll([null], [null]) = [null, null] ArrayUtils.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"]
T
- the component type of the arrayarray1
- the first array whose elements are added to the new array, may be null
array2
- the second array whose elements are added to the new array, may be null
null
if both arrays are null
.
The type of the new array is the type of the first array,
unless the first array is null, in which case the type is the same as the second array.java.lang.IllegalArgumentException
- if the array types are incompatiblepublic static boolean[] addAll(boolean[] array1, boolean... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1
- the first array whose elements are added to the new array.array2
- the second array whose elements are added to the new array.public static char[] addAll(char[] array1, char... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1
- the first array whose elements are added to the new array.array2
- the second array whose elements are added to the new array.public static byte[] addAll(byte[] array1, byte... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1
- the first array whose elements are added to the new array.array2
- the second array whose elements are added to the new array.public static short[] addAll(short[] array1, short... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1
- the first array whose elements are added to the new array.array2
- the second array whose elements are added to the new array.public static int[] addAll(int[] array1, int... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1
- the first array whose elements are added to the new array.array2
- the second array whose elements are added to the new array.public static long[] addAll(long[] array1, long... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1
- the first array whose elements are added to the new array.array2
- the second array whose elements are added to the new array.public static float[] addAll(float[] array1, float... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1
- the first array whose elements are added to the new array.array2
- the second array whose elements are added to the new array.public static double[] addAll(double[] array1, double... array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1
- the first array whose elements are added to the new array.array2
- the second array whose elements are added to the new array.public static <T> T[] add(T[] array, T element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element, unless the element itself is null,
in which case the return type is Object[]
ArrayUtils.add(null, null) = IllegalArgumentException ArrayUtils.add(null, "a") = ["a"] ArrayUtils.add(["a"], null) = ["a", null] ArrayUtils.add(["a"], "b") = ["a", "b"] ArrayUtils.add(["a", "b"], "c") = ["a", "b", "c"]
T
- the component type of the arrayarray
- the array to "add" the element to, may be null
element
- the object to add, may be null
java.lang.IllegalArgumentException
- if both arguments are nullpublic static boolean[] add(boolean[] array, boolean element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, true) = [true] ArrayUtils.add([true], false) = [true, false] ArrayUtils.add([true, false], true) = [true, false, true]
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new arraypublic static byte[] add(byte[] array, byte element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0) = [0] ArrayUtils.add([1], 0) = [1, 0] ArrayUtils.add([1, 0], 1) = [1, 0, 1]
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new arraypublic static char[] add(char[] array, char element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, '0') = ['0'] ArrayUtils.add(['1'], '0') = ['1', '0'] ArrayUtils.add(['1', '0'], '1') = ['1', '0', '1']
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new arraypublic static double[] add(double[] array, double element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0) = [0] ArrayUtils.add([1], 0) = [1, 0] ArrayUtils.add([1, 0], 1) = [1, 0, 1]
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new arraypublic static float[] add(float[] array, float element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0) = [0] ArrayUtils.add([1], 0) = [1, 0] ArrayUtils.add([1, 0], 1) = [1, 0, 1]
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new arraypublic static int[] add(int[] array, int element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0) = [0] ArrayUtils.add([1], 0) = [1, 0] ArrayUtils.add([1, 0], 1) = [1, 0, 1]
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new arraypublic static long[] add(long[] array, long element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0) = [0] ArrayUtils.add([1], 0) = [1, 0] ArrayUtils.add([1, 0], 1) = [1, 0, 1]
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new arraypublic static short[] add(short[] array, short element)
Copies the given array and adds the given element at the end of the new array.
The new array contains the same elements of the input array plus the given element in the last position. The component type of the new array is the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0) = [0] ArrayUtils.add([1], 0) = [1, 0] ArrayUtils.add([1, 0], 1) = [1, 0, 1]
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new array@Deprecated public static <T> T[] add(T[] array, int index, T element)
insert(int, T[], T...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0, null) = IllegalArgumentException ArrayUtils.add(null, 0, "a") = ["a"] ArrayUtils.add(["a"], 1, null) = ["a", null] ArrayUtils.add(["a"], 1, "b") = ["a", "b"] ArrayUtils.add(["a", "b"], 3, "c") = ["a", "b", "c"]
T
- the component type of the arrayarray
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index > array.length).java.lang.IllegalArgumentException
- if both array and element are null@Deprecated public static boolean[] add(boolean[] array, int index, boolean element)
insert(int, boolean[], boolean...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0, true) = [true] ArrayUtils.add([true], 0, false) = [false, true] ArrayUtils.add([false], 1, true) = [false, true] ArrayUtils.add([true, false], 1, true) = [true, true, false]
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index > array.length).@Deprecated public static char[] add(char[] array, int index, char element)
insert(int, char[], char...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add(null, 0, 'a') = ['a'] ArrayUtils.add(['a'], 0, 'b') = ['b', 'a'] ArrayUtils.add(['a', 'b'], 0, 'c') = ['c', 'a', 'b'] ArrayUtils.add(['a', 'b'], 1, 'k') = ['a', 'k', 'b'] ArrayUtils.add(['a', 'b', 'c'], 1, 't') = ['a', 't', 'b', 'c']
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array.length).@Deprecated public static byte[] add(byte[] array, int index, byte element)
insert(int, byte[], byte...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add([1], 0, 2) = [2, 1] ArrayUtils.add([2, 6], 2, 3) = [2, 6, 3] ArrayUtils.add([2, 6], 0, 1) = [1, 2, 6] ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3]
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array.length).@Deprecated public static short[] add(short[] array, int index, short element)
insert(int, short[], short...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add([1], 0, 2) = [2, 1] ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10] ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6] ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3]
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array.length).@Deprecated public static int[] add(int[] array, int index, int element)
insert(int, int[], int...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add([1], 0, 2) = [2, 1] ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10] ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6] ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3]
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array.length).@Deprecated public static long[] add(long[] array, int index, long element)
insert(int, long[], long...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add([1L], 0, 2L) = [2L, 1L] ArrayUtils.add([2L, 6L], 2, 10L) = [2L, 6L, 10L] ArrayUtils.add([2L, 6L], 0, -4L) = [-4L, 2L, 6L] ArrayUtils.add([2L, 6L, 3L], 2, 1L) = [2L, 6L, 1L, 3L]
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array.length).@Deprecated public static float[] add(float[] array, int index, float element)
insert(int, float[], float...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add([1.1f], 0, 2.2f) = [2.2f, 1.1f] ArrayUtils.add([2.3f, 6.4f], 2, 10.5f) = [2.3f, 6.4f, 10.5f] ArrayUtils.add([2.6f, 6.7f], 0, -4.8f) = [-4.8f, 2.6f, 6.7f] ArrayUtils.add([2.9f, 6.0f, 0.3f], 2, 1.0f) = [2.9f, 6.0f, 1.0f, 0.3f]
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array.length).@Deprecated public static double[] add(double[] array, int index, double element)
insert(int, double[], double...)
and
may be removed in a future release. Please note the handling of null
input arrays differs
in the new method: inserting X
into a null
array results in null
not X
.Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, a new one element array is returned
whose component type is the same as the element.
ArrayUtils.add([1.1], 0, 2.2) = [2.2, 1.1] ArrayUtils.add([2.3, 6.4], 2, 10.5) = [2.3, 6.4, 10.5] ArrayUtils.add([2.6, 6.7], 0, -4.8) = [-4.8, 2.6, 6.7] ArrayUtils.add([2.9, 6.0, 0.3], 2, 1.0) = [2.9, 6.0, 1.0, 0.3]
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index > array.length).public static <T> T[] remove(T[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove(["a"], 0) = [] ArrayUtils.remove(["a", "b"], 0) = ["b"] ArrayUtils.remove(["a", "b"], 1) = ["a"] ArrayUtils.remove(["a", "b", "c"], 1) = ["a", "c"]
T
- the component type of the arrayarray
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static <T> T[] removeElement(T[] array, java.lang.Object element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, "a") = null ArrayUtils.removeElement([], "a") = [] ArrayUtils.removeElement(["a"], "b") = ["a"] ArrayUtils.removeElement(["a", "b"], "a") = ["b"] ArrayUtils.removeElement(["a", "b", "a"], "a") = ["b", "a"]
T
- the component type of the arrayarray
- the array to remove the element from, may be null
element
- the element to be removedpublic static boolean[] remove(boolean[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove([true], 0) = [] ArrayUtils.remove([true, false], 0) = [false] ArrayUtils.remove([true, false], 1) = [true] ArrayUtils.remove([true, true, false], 1) = [true, false]
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static boolean[] removeElement(boolean[] array, boolean element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, true) = null ArrayUtils.removeElement([], true) = [] ArrayUtils.removeElement([true], false) = [true] ArrayUtils.removeElement([true, false], false) = [true] ArrayUtils.removeElement([true, false, true], true) = [false, true]
array
- the array to remove the element from, may be null
element
- the element to be removedpublic static byte[] remove(byte[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove([1], 0) = [] ArrayUtils.remove([1, 0], 0) = [0] ArrayUtils.remove([1, 0], 1) = [1] ArrayUtils.remove([1, 0, 1], 1) = [1, 1]
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static byte[] removeElement(byte[] array, byte element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, 1) = null ArrayUtils.removeElement([], 1) = [] ArrayUtils.removeElement([1], 0) = [1] ArrayUtils.removeElement([1, 0], 0) = [1] ArrayUtils.removeElement([1, 0, 1], 1) = [0, 1]
array
- the array to remove the element from, may be null
element
- the element to be removedpublic static char[] remove(char[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove(['a'], 0) = [] ArrayUtils.remove(['a', 'b'], 0) = ['b'] ArrayUtils.remove(['a', 'b'], 1) = ['a'] ArrayUtils.remove(['a', 'b', 'c'], 1) = ['a', 'c']
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static char[] removeElement(char[] array, char element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, 'a') = null ArrayUtils.removeElement([], 'a') = [] ArrayUtils.removeElement(['a'], 'b') = ['a'] ArrayUtils.removeElement(['a', 'b'], 'a') = ['b'] ArrayUtils.removeElement(['a', 'b', 'a'], 'a') = ['b', 'a']
array
- the array to remove the element from, may be null
element
- the element to be removedpublic static double[] remove(double[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove([1.1], 0) = [] ArrayUtils.remove([2.5, 6.0], 0) = [6.0] ArrayUtils.remove([2.5, 6.0], 1) = [2.5] ArrayUtils.remove([2.5, 6.0, 3.8], 1) = [2.5, 3.8]
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static double[] removeElement(double[] array, double element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, 1.1) = null ArrayUtils.removeElement([], 1.1) = [] ArrayUtils.removeElement([1.1], 1.2) = [1.1] ArrayUtils.removeElement([1.1, 2.3], 1.1) = [2.3] ArrayUtils.removeElement([1.1, 2.3, 1.1], 1.1) = [2.3, 1.1]
array
- the array to remove the element from, may be null
element
- the element to be removedpublic static float[] remove(float[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove([1.1], 0) = [] ArrayUtils.remove([2.5, 6.0], 0) = [6.0] ArrayUtils.remove([2.5, 6.0], 1) = [2.5] ArrayUtils.remove([2.5, 6.0, 3.8], 1) = [2.5, 3.8]
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static float[] removeElement(float[] array, float element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, 1.1) = null ArrayUtils.removeElement([], 1.1) = [] ArrayUtils.removeElement([1.1], 1.2) = [1.1] ArrayUtils.removeElement([1.1, 2.3], 1.1) = [2.3] ArrayUtils.removeElement([1.1, 2.3, 1.1], 1.1) = [2.3, 1.1]
array
- the array to remove the element from, may be null
element
- the element to be removedpublic static int[] remove(int[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove([1], 0) = [] ArrayUtils.remove([2, 6], 0) = [6] ArrayUtils.remove([2, 6], 1) = [2] ArrayUtils.remove([2, 6, 3], 1) = [2, 3]
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static int[] removeElement(int[] array, int element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, 1) = null ArrayUtils.removeElement([], 1) = [] ArrayUtils.removeElement([1], 2) = [1] ArrayUtils.removeElement([1, 3], 1) = [3] ArrayUtils.removeElement([1, 3, 1], 1) = [3, 1]
array
- the array to remove the element from, may be null
element
- the element to be removedpublic static long[] remove(long[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove([1], 0) = [] ArrayUtils.remove([2, 6], 0) = [6] ArrayUtils.remove([2, 6], 1) = [2] ArrayUtils.remove([2, 6, 3], 1) = [2, 3]
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static long[] removeElement(long[] array, long element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, 1) = null ArrayUtils.removeElement([], 1) = [] ArrayUtils.removeElement([1], 2) = [1] ArrayUtils.removeElement([1, 3], 1) = [3] ArrayUtils.removeElement([1, 3, 1], 1) = [3, 1]
array
- the array to remove the element from, may be null
element
- the element to be removedpublic static short[] remove(short[] array, int index)
Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).
This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.remove([1], 0) = [] ArrayUtils.remove([2, 6], 0) = [6] ArrayUtils.remove([2, 6], 1) = [2] ArrayUtils.remove([2, 6, 3], 1) = [2, 3]
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static short[] removeElement(short[] array, short element)
Removes the first occurrence of the specified element from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn't contains such an element, no elements are removed from the array.
This method returns a new array with the same elements of the input array except the first occurrence of the specified element. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElement(null, 1) = null ArrayUtils.removeElement([], 1) = [] ArrayUtils.removeElement([1], 2) = [1] ArrayUtils.removeElement([1, 3], 1) = [3] ArrayUtils.removeElement([1, 3, 1], 1) = [3, 1]
array
- the array to remove the element from, may be null
element
- the element to be removedpublic static <T> T[] removeAll(T[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll(["a", "b", "c"], 0, 2) = ["b"] ArrayUtils.removeAll(["a", "b", "c"], 1, 2) = ["a"]
T
- the component type of the arrayarray
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.@SafeVarargs public static <T> T[] removeElements(T[] array, T... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, "a", "b") = null ArrayUtils.removeElements([], "a", "b") = [] ArrayUtils.removeElements(["a"], "b", "c") = ["a"] ArrayUtils.removeElements(["a", "b"], "a", "c") = ["b"] ArrayUtils.removeElements(["a", "b", "a"], "a") = ["b", "a"] ArrayUtils.removeElements(["a", "b", "a"], "a", "a") = ["b"]
T
- the component type of the arrayarray
- the array to remove the element from, may be null
values
- the elements to be removedpublic static byte[] removeAll(byte[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll([1], 0) = [] ArrayUtils.removeAll([2, 6], 0) = [6] ArrayUtils.removeAll([2, 6], 0, 1) = [] ArrayUtils.removeAll([2, 6, 3], 1, 2) = [2] ArrayUtils.removeAll([2, 6, 3], 0, 2) = [6] ArrayUtils.removeAll([2, 6, 3], 0, 1, 2) = []
array
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static byte[] removeElements(byte[] array, byte... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, 1, 2) = null ArrayUtils.removeElements([], 1, 2) = [] ArrayUtils.removeElements([1], 2, 3) = [1] ArrayUtils.removeElements([1, 3], 1, 2) = [3] ArrayUtils.removeElements([1, 3, 1], 1) = [3, 1] ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static short[] removeAll(short[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll([1], 0) = [] ArrayUtils.removeAll([2, 6], 0) = [6] ArrayUtils.removeAll([2, 6], 0, 1) = [] ArrayUtils.removeAll([2, 6, 3], 1, 2) = [2] ArrayUtils.removeAll([2, 6, 3], 0, 2) = [6] ArrayUtils.removeAll([2, 6, 3], 0, 1, 2) = []
array
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static short[] removeElements(short[] array, short... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, 1, 2) = null ArrayUtils.removeElements([], 1, 2) = [] ArrayUtils.removeElements([1], 2, 3) = [1] ArrayUtils.removeElements([1, 3], 1, 2) = [3] ArrayUtils.removeElements([1, 3, 1], 1) = [3, 1] ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static int[] removeAll(int[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll([1], 0) = [] ArrayUtils.removeAll([2, 6], 0) = [6] ArrayUtils.removeAll([2, 6], 0, 1) = [] ArrayUtils.removeAll([2, 6, 3], 1, 2) = [2] ArrayUtils.removeAll([2, 6, 3], 0, 2) = [6] ArrayUtils.removeAll([2, 6, 3], 0, 1, 2) = []
array
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static int[] removeElements(int[] array, int... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, 1, 2) = null ArrayUtils.removeElements([], 1, 2) = [] ArrayUtils.removeElements([1], 2, 3) = [1] ArrayUtils.removeElements([1, 3], 1, 2) = [3] ArrayUtils.removeElements([1, 3, 1], 1) = [3, 1] ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static char[] removeAll(char[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll([1], 0) = [] ArrayUtils.removeAll([2, 6], 0) = [6] ArrayUtils.removeAll([2, 6], 0, 1) = [] ArrayUtils.removeAll([2, 6, 3], 1, 2) = [2] ArrayUtils.removeAll([2, 6, 3], 0, 2) = [6] ArrayUtils.removeAll([2, 6, 3], 0, 1, 2) = []
array
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static char[] removeElements(char[] array, char... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, 1, 2) = null ArrayUtils.removeElements([], 1, 2) = [] ArrayUtils.removeElements([1], 2, 3) = [1] ArrayUtils.removeElements([1, 3], 1, 2) = [3] ArrayUtils.removeElements([1, 3, 1], 1) = [3, 1] ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static long[] removeAll(long[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll([1], 0) = [] ArrayUtils.removeAll([2, 6], 0) = [6] ArrayUtils.removeAll([2, 6], 0, 1) = [] ArrayUtils.removeAll([2, 6, 3], 1, 2) = [2] ArrayUtils.removeAll([2, 6, 3], 0, 2) = [6] ArrayUtils.removeAll([2, 6, 3], 0, 1, 2) = []
array
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static long[] removeElements(long[] array, long... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, 1, 2) = null ArrayUtils.removeElements([], 1, 2) = [] ArrayUtils.removeElements([1], 2, 3) = [1] ArrayUtils.removeElements([1, 3], 1, 2) = [3] ArrayUtils.removeElements([1, 3, 1], 1) = [3, 1] ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static float[] removeAll(float[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll([1], 0) = [] ArrayUtils.removeAll([2, 6], 0) = [6] ArrayUtils.removeAll([2, 6], 0, 1) = [] ArrayUtils.removeAll([2, 6, 3], 1, 2) = [2] ArrayUtils.removeAll([2, 6, 3], 0, 2) = [6] ArrayUtils.removeAll([2, 6, 3], 0, 1, 2) = []
array
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static float[] removeElements(float[] array, float... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, 1, 2) = null ArrayUtils.removeElements([], 1, 2) = [] ArrayUtils.removeElements([1], 2, 3) = [1] ArrayUtils.removeElements([1, 3], 1, 2) = [3] ArrayUtils.removeElements([1, 3, 1], 1) = [3, 1] ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static double[] removeAll(double[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll([1], 0) = [] ArrayUtils.removeAll([2, 6], 0) = [6] ArrayUtils.removeAll([2, 6], 0, 1) = [] ArrayUtils.removeAll([2, 6, 3], 1, 2) = [2] ArrayUtils.removeAll([2, 6, 3], 0, 2) = [6] ArrayUtils.removeAll([2, 6, 3], 0, 1, 2) = []
array
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static double[] removeElements(double[] array, double... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, 1, 2) = null ArrayUtils.removeElements([], 1, 2) = [] ArrayUtils.removeElements([1], 2, 3) = [1] ArrayUtils.removeElements([1, 3], 1, 2) = [3] ArrayUtils.removeElements([1, 3, 1], 1) = [3, 1] ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static boolean[] removeAll(boolean[] array, int... indices)
Removes the elements at the specified positions from the specified array. All remaining elements are shifted to the left.
This method returns a new array with the same elements of the input array except those at the specified positions. The component type of the returned array is always the same as that of the input array.
If the input array is null
, an IndexOutOfBoundsException
will be thrown, because in that case no valid index can be specified.
ArrayUtils.removeAll([true, false, true], 0, 2) = [false] ArrayUtils.removeAll([true, false, true], 1, 2) = [true]
array
- the array to remove the element from, may not be null
indices
- the positions of the elements to be removedjava.lang.IndexOutOfBoundsException
- if any index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static boolean[] removeElements(boolean[] array, boolean... values)
Removes occurrences of specified elements, in specified quantities, from the specified array. All subsequent elements are shifted left. For any element-to-be-removed specified in greater quantities than contained in the original array, no change occurs beyond the removal of the existing matching items.
This method returns a new array with the same elements of the input array except for the earliest-encountered occurrences of the specified elements. The component type of the returned array is always the same as that of the input array.
ArrayUtils.removeElements(null, true, false) = null ArrayUtils.removeElements([], true, false) = [] ArrayUtils.removeElements([true], false, false) = [true] ArrayUtils.removeElements([true, false], true, true) = [false] ArrayUtils.removeElements([true, false, true], true) = [false, true] ArrayUtils.removeElements([true, false, true], true, true) = [false]
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static <T extends java.lang.Comparable<? super T>> boolean isSorted(T[] array)
This method checks whether the provided array is sorted according to the class's
compareTo
method.
T
- the datatype of the array to check, it must implement Comparable
array
- the array to checkpublic static <T> boolean isSorted(T[] array, java.util.Comparator<T> comparator)
This method checks whether the provided array is sorted according to the provided Comparator
.
T
- the datatype of the arrayarray
- the array to checkcomparator
- the Comparator
to compare overpublic static boolean isSorted(int[] array)
This method checks whether the provided array is sorted according to natural ordering.
array
- the array to checkpublic static boolean isSorted(long[] array)
This method checks whether the provided array is sorted according to natural ordering.
array
- the array to checkpublic static boolean isSorted(short[] array)
This method checks whether the provided array is sorted according to natural ordering.
array
- the array to checkpublic static boolean isSorted(double[] array)
This method checks whether the provided array is sorted according to natural ordering.
array
- the array to checkpublic static boolean isSorted(float[] array)
This method checks whether the provided array is sorted according to natural ordering.
array
- the array to checkpublic static boolean isSorted(byte[] array)
This method checks whether the provided array is sorted according to natural ordering.
array
- the array to checkpublic static boolean isSorted(char[] array)
This method checks whether the provided array is sorted according to natural ordering.
array
- the array to checkpublic static boolean isSorted(boolean[] array)
This method checks whether the provided array is sorted according to natural ordering
(false
before true
).
array
- the array to checkpublic static boolean[] removeAllOccurences(boolean[] array, boolean element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
element
- the element to removearray
- the input arraypublic static char[] removeAllOccurences(char[] array, char element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
element
- the element to removearray
- the input arraypublic static byte[] removeAllOccurences(byte[] array, byte element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
element
- the element to removearray
- the input arraypublic static short[] removeAllOccurences(short[] array, short element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
element
- the element to removearray
- the input arraypublic static int[] removeAllOccurences(int[] array, int element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
element
- the element to removearray
- the input arraypublic static long[] removeAllOccurences(long[] array, long element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
element
- the element to removearray
- the input arraypublic static float[] removeAllOccurences(float[] array, float element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
element
- the element to removearray
- the input arraypublic static double[] removeAllOccurences(double[] array, double element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
element
- the element to removearray
- the input arraypublic static <T> T[] removeAllOccurences(T[] array, T element)
All subsequent elements are shifted to the left (subtracts one from their indices).
If the array doesn't contains such an element, no elements are removed from the array.
null
will be returned if the input array is null
.
T
- the type of object in the arrayelement
- the element to removearray
- the input arraypublic static java.lang.String[] toStringArray(java.lang.Object[] array)
Returns an array containing the string representation of each element in the argument array.
This method returns null
for a null
input array.
array
- the Object[]
to be processed, may be nullString[]
of the same size as the source with its element's string representation,
null
if null array inputjava.lang.NullPointerException
- if array contains null
public static java.lang.String[] toStringArray(java.lang.Object[] array, java.lang.String valueForNullElements)
Returns an array containing the string representation of each element in the argument
array handling null
elements.
This method returns null
for a null
input array.
array
- the Object[] to be processed, may be nullvalueForNullElements
- the value to insert if null
is foundString
array, null
if null array inputpublic static boolean[] insert(int index, boolean[] array, boolean... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static byte[] insert(int index, byte[] array, byte... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static char[] insert(int index, char[] array, char... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static double[] insert(int index, double[] array, double... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static float[] insert(int index, float[] array, float... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static int[] insert(int index, int[] array, int... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static long[] insert(int index, long[] array, long... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static short[] insert(int index, short[] array, short... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
@SafeVarargs public static <T> T[] insert(int index, T[] array, T... values)
Inserts elements into an array at the given index (starting from zero).
When an array is returned, it is always a new array.
ArrayUtils.insert(index, null, null) = null ArrayUtils.insert(index, array, null) = cloned copy of 'array' ArrayUtils.insert(index, null, values) = null
T
- The type of elements in array
and values
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
java.lang.IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static void shuffle(java.lang.Object[] array)
array
- the array to shufflepublic static void shuffle(java.lang.Object[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static void shuffle(boolean[] array)
array
- the array to shufflepublic static void shuffle(boolean[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static void shuffle(byte[] array)
array
- the array to shufflepublic static void shuffle(byte[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static void shuffle(char[] array)
array
- the array to shufflepublic static void shuffle(char[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static void shuffle(short[] array)
array
- the array to shufflepublic static void shuffle(short[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static void shuffle(int[] array)
array
- the array to shufflepublic static void shuffle(int[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static void shuffle(long[] array)
array
- the array to shufflepublic static void shuffle(long[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static void shuffle(float[] array)
array
- the array to shufflepublic static void shuffle(float[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static void shuffle(double[] array)
array
- the array to shufflepublic static void shuffle(double[] array, java.util.Random random)
array
- the array to shufflerandom
- the source of randomness used to permute the elementspublic static <T> boolean isArrayIndexValid(T[] array, int index)
T
- the component type of the arrayarray
- the array to inspect, may be nullindex
- the index of the array to be inspected"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"