ArrayUtils¶
- public class org.apache.commons.lang3.ArrayUtils[source]¶
Operations on arrays, primitive arrays (like
int[]) and primitive wrapper arrays (likeInteger[]).This class tries to handle
nullinput gracefully. An exception will not be thrown for anullarray input. However, an Object array that contains anullelement may throw an exception. Each method documents its behavior.#ThreadSafe#
- Since:
2.0
Constructors¶
Deprecated. ArrayUtils instances should NOT be constructed in standard programming. |
- @Deprecated public ArrayUtils()[source]¶
Deprecated: TODO Make private in 4.0.
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.
Fields and constants¶
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
An empty immutable |
|
The index value when an element is not found in a list or array: |
|
The |
|
Deprecated. The |
- public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY[source]¶
An empty immutable
Characterarray.
- public static final Method[] EMPTY_METHOD_ARRAY[source]¶
An empty immutable
Methodarray.- Since:
3.10
- public static final Throwable[] EMPTY_THROWABLE_ARRAY[source]¶
An empty immutable
Throwablearray.- Since:
3.10
- public static final int INDEX_NOT_FOUND = -1[source]¶
The index value when an element is not found in a list or array:
-1. This value is returned by methods in this class and can also be used in comparisons with values returned by various method fromjava.util.List.
- public static final int SAFE_MAX_ARRAY_LENGTH = 2147483639[source]¶
The
MAX_ARRAY_LENGTHconstant from Java’s internal ArraySupport class.- Since:
3.21.0
- @Deprecated public static int SOFT_MAX_ARRAY_LENGTH[source]¶
Deprecated: This variable will be final in 4.0; to guarantee immutability now, use
#SAFE_MAX_ARRAY_LENGTH.The
SOFT_MAX_ARRAY_LENGTHconstant from Java’s internal ArraySupport class.- Since:
3.19.0
Methods¶
Copies the given array and adds the given element at the end of the new array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Copies the given array and adds the given element at the end of the new array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Copies the given array and adds the given element at the end of the new array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Copies the given array and adds the given element at the end of the new array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Copies the given array and adds the given element at the end of the new array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Copies the given array and adds the given element at the end of the new array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Copies the given array and adds the given element at the end of the new array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Copies the given array and adds the given element at the end of the new array. |
|
Deprecated. Inserts the specified element at the specified position in the array. |
|
Copies the given array and adds the given element at the end of the new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Adds all the elements of the given arrays into a new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
Copies the given array and adds the given element at the beginning of the new array. |
|
A fluent version of |
|
A fluent version of |
|
A fluent version of |
|
Clones an array or returns |
|
Clones an array or returns |
|
Clones an array or returns |
|
Clones an array or returns |
|
Clones an array or returns |
|
Clones an array or returns |
|
Shallow clones an array or returns |
|
Clones an array or returns |
|
Clones an array or returns |
|
Concatenates multiple boolean arrays into a single array. |
|
Concatenates multiple byte arrays into a single array. |
|
Concatenates multiple char arrays into a single array. |
|
Concatenates multiple double arrays into a single array. |
|
Concatenates multiple float arrays into a single array. |
|
Concatenates multiple int arrays into a single array. |
|
Concatenates multiple long arrays into a single array. |
|
Concatenates multiple short arrays into a single array. |
|
Checks if the value is in the given array. |
|
Checks if the value is in the given array. |
|
Checks if the value is in the given array. |
|
Checks if the value is in the given array. |
|
Checks if a value falling within the given tolerance is in the given array. |
|
Checks if the value is in the given array. |
|
Checks if the value is in the given array. |
|
Checks if the object is in the given array. |
|
Checks if the value is in the given array. |
|
Checks if the value is in the given array. |
|
Checks if any of the ints are in the given array. |
|
Checks if any of the objects are in the given array. |
|
Gets the nTh element of an array or null if the index is out of bounds or the array is null. |
|
Gets the nTh element of an array or a default value if the index is out of bounds. |
|
Gets an array’s component type. |
|
Gets the number of dimensions of an array. |
|
Gets the length of the specified array. |
|
Gets a hash code for an array handling multidimensional arrays. |
|
Finds the index of the given value in the array. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the index of the given value in the array. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the index of the given value in the array. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the index of the given value in the array. |
|
Finds the index of the given value within a given tolerance in the array. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the index of the given value in the array. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the index of the given value in the array. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the index of the given object in the array. |
|
Finds the index of the given object in the array starting at the given index. |
|
Finds the index of the given value in the array. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the index of the given value in the array. |
|
Finds the index of the given value in the array starting at the given index. |
|
Finds the indices of the given value in the array. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Finds the indices of the given value in the array. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Finds the indices of the given value in the array. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Finds the indices of the given value in the array. |
|
Finds the indices of the given value within a given tolerance in the array. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Finds the indices of the given value in the array. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Finds the indices of the given value in the array. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Finds the indices of the given object in the array. |
|
Finds the indices of the given object in the array starting at the given index. |
|
Finds the indices of the given value in the array. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Finds the indices of the given value in the array. |
|
Finds the indices of the given value in the array starting at the given index. |
|
Inserts elements into an array at the given index (starting from zero). |
|
Inserts elements into an array at the given index (starting from zero). |
|
Inserts elements into an array at the given index (starting from zero). |
|
Inserts elements into an array at the given index (starting from zero). |
|
Inserts elements into an array at the given index (starting from zero). |
|
Inserts elements into an array at the given index (starting from zero). |
|
Inserts elements into an array at the given index (starting from zero). |
|
Inserts elements into an array at the given index (starting from zero). |
|
Inserts elements into an array at the given index (starting from zero). |
|
Tests whether a given array can safely be accessed at the given index. |
|
Tests whether an array of primitive booleans is empty or |
|
Tests whether an array of primitive bytes is empty or |
|
Tests whether an array of primitive chars is empty or |
|
Tests whether an array of primitive doubles is empty or |
|
Tests whether an array of primitive floats is empty or |
|
Tests whether an array of primitive ints is empty or |
|
Tests whether an array of Objects is empty or |
|
Tests whether an array of primitive longs is empty or |
|
Tests whether an array of primitive shorts is empty or |
|
Deprecated. Tests whether two arrays have equal content, using equals(), handling multidimensional arrays correctly. |
|
Tests whether an array of primitive booleans is not empty and not |
|
Tests whether an array of primitive bytes is not empty and not |
|
Tests whether an array of primitive chars is not empty and not |
|
Tests whether an array of primitive doubles is not empty and not |
|
Tests whether an array of primitive floats is not empty and not |
|
Tests whether an array of primitive ints is not empty and not |
|
Tests whether an array of Objects is not empty and not |
|
Tests whether an array of primitive longs is not empty and not |
|
Tests whether an array of primitive shorts is not empty and not |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same length, treating |
|
Tests whether two arrays are the same type taking into account multidimensional arrays. |
|
Tests whether the provided array is sorted according to natural ordering ( |
|
Tests whether the provided array is sorted according to natural ordering. |
|
Tests whether the provided array is sorted according to natural ordering. |
|
Tests whether the provided array is sorted according to natural ordering. |
|
Tests whether the provided array is sorted according to natural ordering. |
|
Tests whether the provided array is sorted according to natural ordering. |
|
Tests whether the provided array is sorted according to the class’s |
|
Tests whether the provided array is sorted according to the provided |
|
Tests whether the provided array is sorted according to natural ordering. |
|
Tests whether the provided array is sorted according to natural ordering. |
|
Finds the last index of the given value within the array. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Finds the last index of the given value within the array. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Finds the last index of the given value within the array. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Finds the last index of the given value within the array. |
|
Finds the last index of the given value within a given tolerance in the array. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Finds the last index of the given value within the array. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Finds the last index of the given value within the array. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Finds the last index of the given object within the array. |
|
Finds the last index of the given object in the array starting at the given index. |
|
Finds the last index of the given value within the array. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Finds the last index of the given value within the array. |
|
Finds the last index of the given value in the array starting at the given index. |
|
Delegates to |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Defensive programming technique to change a |
|
Removes the element at the specified position from the specified array. |
|
Removes the element at the specified position from the specified array. |
|
Removes the element at the specified position from the specified array. |
|
Removes the element at the specified position from the specified array. |
|
Removes the element at the specified position from the specified array. |
|
Removes the element at the specified position from the specified array. |
|
Removes the element at the specified position from the specified array. |
|
Removes the element at the specified position from the specified array. |
|
Removes the element at the specified position from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Removes the elements at the specified positions from the specified array. |
|
Deprecated. Removes the occurrences of the specified element from the specified boolean array. |
|
Deprecated. Removes the occurrences of the specified element from the specified byte array. |
|
Deprecated. Removes the occurrences of the specified element from the specified char array. |
|
Deprecated. Removes the occurrences of the specified element from the specified double array. |
|
Deprecated. Removes the occurrences of the specified element from the specified float array. |
|
Deprecated. Removes the occurrences of the specified element from the specified int array. |
|
Deprecated. Removes the occurrences of the specified element from the specified array. |
|
Deprecated. Removes the occurrences of the specified element from the specified long array. |
|
Deprecated. Removes the occurrences of the specified element from the specified short array. |
|
Removes the occurrences of the specified element from the specified boolean array. |
|
Removes the occurrences of the specified element from the specified byte array. |
|
Removes the occurrences of the specified element from the specified char array. |
|
Removes the occurrences of the specified element from the specified double array. |
|
Removes the occurrences of the specified element from the specified float array. |
|
Removes the occurrences of the specified element from the specified int array. |
|
Removes the occurrences of the specified element from the specified array. |
|
Removes the occurrences of the specified element from the specified long array. |
|
Removes the occurrences of the specified element from the specified short array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes the first occurrence of the specified element from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Removes occurrences of specified elements, in specified quantities, from the specified array. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Reverses the order of the given array. |
|
Reverses the order of the given array in the given range. |
|
Sets all elements of the specified array, using the provided generator supplier to compute each element. |
|
Sets all elements of the specified array, using the provided generator supplier to compute each element. |
|
Shifts the order of the given boolean array. |
|
Shifts the order of a series of elements in the given boolean array. |
|
Shifts the order of the given byte array. |
|
Shifts the order of a series of elements in the given byte array. |
|
Shifts the order of the given char array. |
|
Shifts the order of a series of elements in the given char array. |
|
Shifts the order of the given double array. |
|
Shifts the order of a series of elements in the given double array. |
|
Shifts the order of the given float array. |
|
Shifts the order of a series of elements in the given float array. |
|
Shifts the order of the given int array. |
|
Shifts the order of a series of elements in the given int array. |
|
Shifts the order of the given array. |
|
Shifts the order of a series of elements in the given array. |
|
Shifts the order of the given long array. |
|
Shifts the order of a series of elements in the given long array. |
|
Shifts the order of the given short array. |
|
Shifts the order of a series of elements in the given short array. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm. |
|
Tests whether the given data array starts with an expected array, for example, signature bytes. |
|
Produces a new |
|
Produces a new |
|
Produces a new |
|
Produces a new |
|
Produces a new |
|
Produces a new |
|
Produces a new array containing the elements between the start and end indices. |
|
Produces a new |
|
Produces a new |
|
Swaps two elements in the given boolean array. |
|
Swaps a series of elements in the given boolean array. |
|
Swaps two elements in the given byte array. |
|
Swaps a series of elements in the given byte array. |
|
Swaps two elements in the given char array. |
|
Swaps a series of elements in the given char array. |
|
Swaps two elements in the given double array. |
|
Swaps a series of elements in the given double array. |
|
Swaps two elements in the given float array. |
|
Swaps a series of elements in the given float array. |
|
Swaps two elements in the given int array. |
|
Swaps a series of elements in the given int array. |
|
Swaps two elements in the given array. |
|
Swaps a series of elements in the given array. |
|
Swaps two elements in the given long array. |
|
Swaps a series of elements in the given long array. |
|
Swaps two elements in the given short array. |
|
Swaps a series of elements in the given short array. |
|
Create a type-safe generic array. |
|
Converts the given array into a |
|
Converts an array of primitive booleans to objects. |
|
Converts an array of primitive bytes to objects. |
|
Converts an array of primitive chars to objects. |
|
Converts an array of primitive doubles to objects. |
|
Converts an array of primitive floats to objects. |
|
Converts an array of primitive ints to objects. |
|
Converts an array of primitive longs to objects. |
|
Converts an array of primitive shorts to objects. |
|
Converts an array of object Booleans to primitives. |
|
Converts an array of object Booleans to primitives handling |
|
Converts an array of object Bytes to primitives. |
|
Converts an array of object Bytes to primitives handling |
|
Converts an array of object Characters to primitives. |
|
Converts an array of object Character to primitives handling |
|
Converts an array of object Doubles to primitives. |
|
Converts an array of object Doubles to primitives handling |
|
Converts an array of object Floats to primitives. |
|
Converts an array of object Floats to primitives handling |
|
Converts an array of object Integers to primitives. |
|
Converts an array of object Integer to primitives handling |
|
Converts an array of object Longs to primitives. |
|
Converts an array of object Long to primitives handling |
|
Create an array of primitive type from an array of wrapper types. |
|
Converts an array of object Shorts to primitives. |
|
Converts an array of object Short to primitives handling |
|
Outputs an array as a String, treating |
|
Outputs an array as a String handling |
|
Returns an array containing the string representation of each element in the argument array. |
|
Returns an array containing the string representation of each element in the argument array handling |
- public static boolean[] add(boolean[] array, boolean element)[source]¶
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]
- Parameters:
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.
- Returns:
A new array containing the existing elements plus the new element.
- Since:
2.1
- @Deprecated public static boolean[] add(boolean[] array, int index, boolean element)[source]¶
Deprecated: this method has been superseded by
#insert(int, boolean[], boolean...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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]
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index > array.length).
- public static byte[] add(byte[] array, byte element)[source]¶
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]
- Parameters:
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.
- Returns:
A new array containing the existing elements plus the new element.
- Since:
2.1
- @Deprecated public static byte[] add(byte[] array, int index, byte element)[source]¶
Deprecated: this method has been superseded by
#insert(int, byte[], byte...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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]
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range. (index < 0 || index > array.length).
- public static char[] add(char[] array, char element)[source]¶
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']
- Parameters:
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.
- Returns:
A new array containing the existing elements plus the new element.
- Since:
2.1
- @Deprecated public static char[] add(char[] array, int index, char element)[source]¶
Deprecated: this method has been superseded by
#insert(int, char[], char...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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']
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range. (index < 0 || index > array.length).
- public static double[] add(double[] array, double element)[source]¶
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]
- Parameters:
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.
- Returns:
A new array containing the existing elements plus the new element.
- Since:
2.1
- @Deprecated public static double[] add(double[] array, int index, double element)[source]¶
Deprecated: this method has been superseded by
#insert(int, double[], double...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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]
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index > array.length).
- public static float[] add(float[] array, float element)[source]¶
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]
- Parameters:
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.
- Returns:
A new array containing the existing elements plus the new element.
- Since:
2.1
- @Deprecated public static float[] add(float[] array, int index, float element)[source]¶
Deprecated: this method has been superseded by
#insert(int, float[], float...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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]
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index > array.length).
- public static int[] add(int[] array, int element)[source]¶
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]
- Parameters:
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.
- Returns:
A new array containing the existing elements plus the new element.
- Since:
2.1
- @Deprecated public static int[] add(int[] array, int index, int element)[source]¶
Deprecated: this method has been superseded by
#insert(int, int[], int...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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]
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index > array.length).
- @Deprecated public static <T> T[] add(T[] array, int index, T element)[source]¶
Deprecated: this method has been superseded by
insert(int, T[], T...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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) = Throws 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"]
- Type parameters:
<T> – The component type of the array.
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index > array.length).
java.lang.IllegalArgumentException – Thrown if both array and element are null.
- public static <T> T[] add(T[] array, T element)[source]¶
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) = Throws 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"]
- Type parameters:
<T> – The component type of the array.
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add, may be
null.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element. If both are null, an IllegalArgumentException is thrown.
- Throws:
java.lang.IllegalArgumentException – Thrown if both arguments are null.
- Since:
2.1
- @Deprecated public static long[] add(long[] array, int index, long element)[source]¶
Deprecated: this method has been superseded by
#insert(int, long[], long...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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]
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index > array.length).
- public static long[] add(long[] array, long element)[source]¶
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]
- Parameters:
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.
- Returns:
A new array containing the existing elements plus the new element.
- Since:
2.1
- @Deprecated public static short[] add(short[] array, int index, short element)[source]¶
Deprecated: this method has been superseded by
#insert(int, short[], short...)and may be removed in a future release. Please note the handling ofnullinput arrays differs in the new method: insertingXinto anullarray results innullnotX.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]
- Parameters:
array – The array to add the element to, may be
null.index – The position of the new object.
element – The object to add.
- Returns:
A new array containing the existing elements and the new element.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index > array.length).
- public static short[] add(short[] array, short element)[source]¶
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]
- Parameters:
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.
- Returns:
A new array containing the existing elements plus the new element.
- Since:
2.1
- public static boolean[] addAll(boolean[] array1, boolean... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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([], []) = [] ArrayUtils.addAll(null, null) = null
- Parameters:
array1 – The first array whose elements are added to the new array.
array2 – The second array whose elements are added to the new array.
- Returns:
The new boolean[] array or
null.- Throws:
java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static byte[] addAll(byte[] array1, byte... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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([], []) = [] ArrayUtils.addAll(null, null) = null
- Parameters:
array1 – The first array whose elements are added to the new array.
array2 – The second array whose elements are added to the new array.
- Returns:
The new byte[] array or
null.- Throws:
java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static char[] addAll(char[] array1, char... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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([], []) = [] ArrayUtils.addAll(null, null) = null
- Parameters:
array1 – The first array whose elements are added to the new array.
array2 – The second array whose elements are added to the new array.
- Returns:
The new char[] array or
null.- Throws:
java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static double[] addAll(double[] array1, double... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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([], []) = [] ArrayUtils.addAll(null, null) = null
- Parameters:
array1 – The first array whose elements are added to the new array.
array2 – The second array whose elements are added to the new array.
- Returns:
The new double[] array or
null.- Throws:
java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static float[] addAll(float[] array1, float... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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([], []) = [] ArrayUtils.addAll(null, null) = null
- Parameters:
array1 – The first array whose elements are added to the new array.
array2 – The second array whose elements are added to the new array.
- Returns:
The new float[] array or
null.- Throws:
java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static int[] addAll(int[] array1, int... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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([], []) = [] ArrayUtils.addAll(null, null) = null
- Parameters:
array1 – The first array whose elements are added to the new array.
array2 – The second array whose elements are added to the new array.
- Returns:
The new int[] array or
null.- Throws:
java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static <T> T[] addAll(T[] array1, @SuppressWarnings({"unchecked"}) T... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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 ArrayUtils.addAll([null], [null]) = [null, null] ArrayUtils.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"]
- Type parameters:
<T> – The component type of the array.
- Parameters:
array1 – 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.
- Returns:
The new array,
nullif both arrays arenull. 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.- Throws:
java.lang.IllegalArgumentException – Thrown if the array types are incompatible or if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static long[] addAll(long[] array1, long... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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([], []) = [] ArrayUtils.addAll(null, null) = null
- Parameters:
array1 – The first array whose elements are added to the new array.
array2 – The second array whose elements are added to the new array.
- Returns:
The new long[] array or
null.- Throws:
java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static short[] addAll(short[] array1, short... array2)[source]¶
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of
array1followed by all of the elementsarray2. 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([], []) = [] ArrayUtils.addAll(null, null) = null
- Parameters:
array1 – The first array whose elements are added to the new array.
array2 – The second array whose elements are added to the new array.
- Returns:
The new short[] array or
null.- Throws:
java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.- Since:
2.1
- public static boolean[] addFirst(boolean[] array, boolean element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, true) = [true] ArrayUtils.addFirst([true], false) = [false, true] ArrayUtils.addFirst([true, false], true) = [true, true, false]
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element.
- Since:
3.10
- public static byte[] addFirst(byte[] array, byte element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, 1) = [1] ArrayUtils.addFirst([1], 0) = [0, 1] ArrayUtils.addFirst([1, 0], 1) = [1, 1, 0]
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element.
- Since:
3.10
- public static char[] addFirst(char[] array, char element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, '1') = ['1'] ArrayUtils.addFirst(['1'], '0') = ['0', '1'] ArrayUtils.addFirst(['1', '0'], '1') = ['1', '1', '0']
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element.
- Since:
3.10
- public static double[] addFirst(double[] array, double element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, 1) = [1] ArrayUtils.addFirst([1], 0) = [0, 1] ArrayUtils.addFirst([1, 0], 1) = [1, 1, 0]
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element.
- Since:
3.10
- public static float[] addFirst(float[] array, float element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, 1) = [1] ArrayUtils.addFirst([1], 0) = [0, 1] ArrayUtils.addFirst([1, 0], 1) = [1, 1, 0]
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element.
- Since:
3.10
- public static int[] addFirst(int[] array, int element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, 1) = [1] ArrayUtils.addFirst([1], 0) = [0, 1] ArrayUtils.addFirst([1, 0], 1) = [1, 1, 0]
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element.
- Since:
3.10
- public static <T> T[] addFirst(T[] array, T element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, null) = Throws IllegalArgumentException ArrayUtils.addFirst(null, "a") = ["a"] ArrayUtils.addFirst(["a"], null) = [null, "a"] ArrayUtils.addFirst(["a"], "b") = ["b", "a"] ArrayUtils.addFirst(["a", "b"], "c") = ["c", "a", "b"]
- Type parameters:
<T> – The component type of the array.
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add, may be
null.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element. If both are null, an IllegalArgumentException is thrown.
- Throws:
java.lang.IllegalArgumentException – Thrown if both arguments are null.
- Since:
3.10
- public static long[] addFirst(long[] array, long element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, 1) = [1] ArrayUtils.addFirst([1], 0) = [0, 1] ArrayUtils.addFirst([1, 0], 1) = [1, 1, 0]
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element.
- Since:
3.10
- public static short[] addFirst(short[] array, short element)[source]¶
Copies the given array and adds the given element at the beginning of the new array.
The new array contains the same elements of the input array plus the given element in the first 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.addFirst(null, 1) = [1] ArrayUtils.addFirst([1], 0) = [0, 1] ArrayUtils.addFirst([1, 0], 1) = [1, 1, 0]
- Parameters:
array – The array to “add” the element to, may be
null.element – The object to add.
- Returns:
A new array containing the existing elements plus the new element The returned array type will be that of the input array (unless null), in which case it will have the same type as the element.
- Since:
3.10
- public static <T> T arraycopy(T source, int sourcePos, int destPos, int length, Function<Integer, T> allocator)[source]¶
A fluent version of
System#arraycopy(Object, int, Object, int, int)that returns the destination array.- Type parameters:
<T> – the type.
- Parameters:
source – The source array.
sourcePos – starting position in the source array.
destPos – starting position in the destination data.
length – The number of array elements to be copied.
allocator – allocates the array to populate and return.
- Returns:
dest
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if copying would cause access of data outside array bounds.
java.lang.ArrayStoreException – Thrown if an element in the
srcarray could not be stored into thedestarray because of a type mismatch.java.lang.NullPointerException – Thrown if either
srcordestisnull.
- Since:
3.15.0
- public static <T> T arraycopy(T source, int sourcePos, int destPos, int length, Supplier<T> allocator)[source]¶
A fluent version of
System#arraycopy(Object, int, Object, int, int)that returns the destination array.- Type parameters:
<T> – the type.
- Parameters:
source – The source array.
sourcePos – starting position in the source array.
destPos – starting position in the destination data.
length – The number of array elements to be copied.
allocator – allocates the array to populate and return.
- Returns:
dest
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if copying would cause access of data outside array bounds.
java.lang.ArrayStoreException – Thrown if an element in the
srcarray could not be stored into thedestarray because of a type mismatch.java.lang.NullPointerException – Thrown if either
srcordestisnull.
- Since:
3.15.0
- public static <T> T arraycopy(T source, int sourcePos, T dest, int destPos, int length)[source]¶
A fluent version of
System#arraycopy(Object, int, Object, int, int)that returns the destination array.- Type parameters:
<T> – the type.
- Parameters:
source – The source array.
sourcePos – starting position in the source array.
dest – The destination array.
destPos – starting position in the destination data.
length – The number of array elements to be copied.
- Returns:
dest
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if copying would cause access of data outside array bounds.
java.lang.ArrayStoreException – Thrown if an element in the
srcarray could not be stored into thedestarray because of a type mismatch.java.lang.NullPointerException – Thrown if either
srcordestisnull.
- Since:
3.15.0
- public static boolean[] clone(boolean[] array)[source]¶
Clones an array or returns
null.This method returns
nullfor anullinput array.- Parameters:
array – The array to clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static byte[] clone(byte[] array)[source]¶
Clones an array or returns
null.This method returns
nullfor anullinput array.- Parameters:
array – The array to clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static char[] clone(char[] array)[source]¶
Clones an array or returns
null.This method returns
nullfor anullinput array.- Parameters:
array – The array to clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static double[] clone(double[] array)[source]¶
Clones an array or returns
null.This method returns
nullfor anullinput array.- Parameters:
array – The array to clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static float[] clone(float[] array)[source]¶
Clones an array or returns
null.This method returns
nullfor anullinput array.- Parameters:
array – The array to clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static int[] clone(int[] array)[source]¶
Clones an array or returns
null.This method returns
nullfor anullinput array.- Parameters:
array – The array to clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static <T> T[] clone(T[] array)[source]¶
Shallow clones an array or returns
null.The objects in the array are not cloned, thus there is no special handling for multi-dimensional arrays.
This method returns
nullfor anullinput array.- Type parameters:
<T> – the component type of the array.
- Parameters:
array – The array to shallow clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static long[] clone(long[] array)[source]¶
Clones an array or returns
null.This method returns
nullfor anullinput array.- Parameters:
array – The array to clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static short[] clone(short[] array)[source]¶
Clones an array or returns
null.This method returns
nullfor anullinput array.- Parameters:
array – The array to clone, may be
null.- Returns:
The cloned array,
nullifnullinput.
- public static boolean[] concat(boolean[]... arrays)[source]¶
Concatenates multiple boolean arrays into a single array.
This method combines all input arrays in the order they are provided, creating a new array that contains all elements from the input arrays. The resulting array length is the sum of lengths of all non-null input arrays.
- Parameters:
arrays – The arrays to concatenate. Can be empty, contain nulls, or be null itself (treated as empty varargs).
- Returns:
A new boolean array containing all elements from the input arrays in the order they appear, or an empty array if no elements are present.
- Throws:
java.lang.NullPointerException – Thrown if the input array of arrays is null.
java.lang.IllegalArgumentException – Thrown if total arrays length exceed
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.21.0
- public static byte[] concat(byte[]... arrays)[source]¶
Concatenates multiple byte arrays into a single array.
This method combines all input arrays in the order they are provided, creating a new array that contains all elements from the input arrays. The resulting array length is the sum of lengths of all non-null input arrays.
- Parameters:
arrays – The arrays to concatenate. Can be empty, contain nulls, or be null itself (treated as empty varargs).
- Returns:
A new byte array containing all elements from the input arrays in the order they appear, or an empty array if no elements are present.
- Throws:
java.lang.NullPointerException – Thrown if the input array of arrays is null.
java.lang.IllegalArgumentException – Thrown if total arrays length exceed
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.21.0
- public static char[] concat(char[]... arrays)[source]¶
Concatenates multiple char arrays into a single array.
This method combines all input arrays in the order they are provided, creating a new array that contains all elements from the input arrays. The resulting array length is the sum of lengths of all non-null input arrays.
- Parameters:
arrays – The arrays to concatenate. Can be empty, contain nulls, or be null itself (treated as empty varargs).
- Returns:
A new char array containing all elements from the input arrays in the order they appear, or an empty array if no elements are present.
- Throws:
java.lang.NullPointerException – Thrown if the input array of arrays is null.
java.lang.IllegalArgumentException – Thrown if total arrays length exceed
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.21.0
- public static double[] concat(double[]... arrays)[source]¶
Concatenates multiple double arrays into a single array.
This method combines all input arrays in the order they are provided, creating a new array that contains all elements from the input arrays. The resulting array length is the sum of lengths of all non-null input arrays.
- Parameters:
arrays – The arrays to concatenate. Can be empty, contain nulls, or be null itself (treated as empty varargs).
- Returns:
A new double array containing all elements from the input arrays in the order they appear, or an empty array if no elements are present.
- Throws:
java.lang.NullPointerException – Thrown if the input array of arrays is null.
java.lang.IllegalArgumentException – Thrown if total arrays length exceed
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.21.0
- public static float[] concat(float[]... arrays)[source]¶
Concatenates multiple float arrays into a single array.
This method combines all input arrays in the order they are provided, creating a new array that contains all elements from the input arrays. The resulting array length is the sum of lengths of all non-null input arrays.
- Parameters:
arrays – The arrays to concatenate. Can be empty, contain nulls, or be null itself (treated as empty varargs).
- Returns:
A new float array containing all elements from the input arrays in the order they appear, or an empty array if no elements are present.
- Throws:
java.lang.NullPointerException – Thrown if the input array of arrays is null.
java.lang.IllegalArgumentException – Thrown if total arrays length exceed
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.21.0
- public static int[] concat(int[]... arrays)[source]¶
Concatenates multiple int arrays into a single array.
This method combines all input arrays in the order they are provided, creating a new array that contains all elements from the input arrays. The resulting array length is the sum of lengths of all non-null input arrays.
- Parameters:
arrays – The arrays to concatenate. Can be empty, contain nulls, or be null itself (treated as empty varargs).
- Returns:
A new int array containing all elements from the input arrays in the order they appear, or an empty array if no elements are present.
- Throws:
java.lang.NullPointerException – Thrown if the input array of arrays is null.
java.lang.IllegalArgumentException – Thrown if total arrays length exceed
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.21.0
- public static long[] concat(long[]... arrays)[source]¶
Concatenates multiple long arrays into a single array.
This method combines all input arrays in the order they are provided, creating a new array that contains all elements from the input arrays. The resulting array length is the sum of lengths of all non-null input arrays.
- Parameters:
arrays – The arrays to concatenate. Can be empty, contain nulls, or be null itself (treated as empty varargs).
- Returns:
A new long array containing all elements from the input arrays in the order they appear, or an empty array if no elements are present.
- Throws:
java.lang.NullPointerException – Thrown if the input array of arrays is null.
java.lang.IllegalArgumentException – Thrown if total arrays length exceed
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.21.0
- public static short[] concat(short[]... arrays)[source]¶
Concatenates multiple short arrays into a single array.
This method combines all input arrays in the order they are provided, creating a new array that contains all elements from the input arrays. The resulting array length is the sum of lengths of all non-null input arrays.
- Parameters:
arrays – The arrays to concatenate. Can be empty, contain nulls, or be null itself (treated as empty varargs).
- Returns:
A new short array containing all elements from the input arrays in the order they appear, or an empty array if no elements are present.
- Throws:
java.lang.NullPointerException – Thrown if the input array of arrays is null.
java.lang.IllegalArgumentException – Thrown if total arrays length exceed
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.21.0
- public static boolean contains(boolean[] array, boolean valueToFind)[source]¶
Checks if the value is in the given array.
The method returns
falseif anullarray is passed in.- Parameters:
array – The array to search.
valueToFind – The value to find.
- Returns:
trueif the array contains the object.
- public static boolean contains(byte[] array, byte valueToFind)[source]¶
Checks if the value is in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(byte[])andArrays#binarySearch(byte[], byte).- Parameters:
array – The array to search.
valueToFind – The value to find.
- Returns:
trueif the array contains the object.
- public static boolean contains(char[] array, char valueToFind)[source]¶
Checks if the value is in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(char[])andArrays#binarySearch(char[], char).- Parameters:
array – The array to search.
valueToFind – The value to find.
- Returns:
trueif the array contains the object.- Since:
2.1
- public static boolean contains(double[] array, double valueToFind)[source]¶
Checks if the value is in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(double[])andArrays#binarySearch(double[], double).- Parameters:
array – The array to search.
valueToFind – The value to find.
- Returns:
trueif the array contains the object.
- public static boolean contains(double[] array, double valueToFind, double tolerance)[source]¶
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
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(double[])andArrays#binarySearch(double[], double).- Parameters:
array – The array to search.
valueToFind – The value to find.
tolerance – The array contains the tolerance of the search.
- Returns:
true if value falling within tolerance is in array.
- public static boolean contains(float[] array, float valueToFind)[source]¶
Checks if the value is in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(float[])andArrays#binarySearch(float[], float).- Parameters:
array – The array to search.
valueToFind – The value to find.
- Returns:
trueif the array contains the object.
- public static boolean contains(int[] array, int valueToFind)[source]¶
Checks if the value is in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(int[])andArrays#binarySearch(int[], int).- Parameters:
array – The array to search.
valueToFind – The value to find.
- Returns:
trueif the array contains the object.
- public static boolean contains(Object[] array, Object objectToFind)[source]¶
Checks if the object is in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(Object[], Comparator)andArrays#binarySearch(Object[], Object).- Parameters:
array – The array to search, may be
null.objectToFind – The object to find, may be
null.
- Returns:
trueif the array contains the object.
- public static boolean contains(long[] array, long valueToFind)[source]¶
Checks if the value is in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(long[])andArrays#binarySearch(long[], long).- Parameters:
array – The array to search.
valueToFind – The value to find.
- Returns:
trueif the array contains the object.
- public static boolean contains(short[] array, short valueToFind)[source]¶
Checks if the value is in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(short[])andArrays#binarySearch(short[], short).- Parameters:
array – The array to search.
valueToFind – The value to find.
- Returns:
trueif the array contains the object.
- public static boolean containsAny(int[] array, int... objectsToFind)[source]¶
Checks if any of the ints are in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(int[])andArrays#binarySearch(int[], int).- Parameters:
array – The array to search.
objectsToFind – any of the ints to find.
- Returns:
trueif the array contains any of the ints.- Since:
3.18.0
- public static boolean containsAny(Object[] array, Object... objectsToFind)[source]¶
Checks if any of the objects are in the given array.
The method returns
falseif anullarray is passed in.If the
arrayelements you are searching implementComparator, consider whether it is worth usingArrays#sort(Object[], Comparator)andArrays#binarySearch(Object[], Object).- Parameters:
array – The array to search, may be
null.objectsToFind – any of the objects to find, may be
null.
- Returns:
trueif the array contains any of the objects.- Since:
3.13.0
- public static <T> T get(T[] array, int index)[source]¶
Gets the nTh element of an array or null if the index is out of bounds or the array is null.
- Type parameters:
<T> – The type of array elements.
- Parameters:
array – The array to index.
index – The index.
- Returns:
The nTh element of an array or null if the index is out of bounds or the array is null.
- Since:
3.11
- public static <T> T get(T[] array, int index, T defaultValue)[source]¶
Gets the nTh element of an array or a default value if the index is out of bounds.
- Type parameters:
<T> – The type of array elements.
- Parameters:
array – The array to index.
index – The index.
defaultValue – The return value of the given index is out of bounds.
- Returns:
The nTh element of an array or a default value if the index is out of bounds.
- Since:
3.11
- public static <T> Class<T> getComponentType(T[] array)[source]¶
Gets an array’s component type.
- Type parameters:
<T> – The array type.
- Parameters:
array – The array.
- Returns:
The component type.
- Since:
3.13.0
- public static int getDimensions(Object array)[source]¶
Gets the number of dimensions of an array.
The JVM specification limits the number of dimensions to 255.
- Parameters:
array – The array, may be
null.- Returns:
The number of dimensions, 0 if the input is null or not an array. The JVM specification limits the number of dimensions to 255.
- Since:
3.21.0
- See also:
- public static int getLength(Object array)[source]¶
Gets the length of the specified array. This method handles
Objectarrays and primitive arrays.If the input array is
null,0is 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
- Parameters:
array – The array to retrieve the length from, may be
null.- Returns:
The length of the array, or
0if the array isnull.- Throws:
java.lang.IllegalArgumentException – Thrown if the object argument is not an array.
- Since:
2.1
- public static int hashCode(Object array)[source]¶
Gets a hash code for an array handling multidimensional arrays.
Multi-dimensional primitive arrays are also handled by this method.
- Parameters:
array – The array to get a hash code for, may be
null.- Returns:
A hash code for the array.
- See also:
- public static int indexOf(boolean[] array, boolean valueToFind)[source]¶
Finds the index of the given value in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(boolean[] array, boolean valueToFind, int startIndex)[source]¶
Finds the index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(byte[] array, byte valueToFind)[source]¶
Finds the index of the given value in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(byte[] array, byte valueToFind, int startIndex)[source]¶
Finds the index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(char[] array, char valueToFind)[source]¶
Finds the index of the given value in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.- Since:
2.1
- public static int indexOf(char[] array, char valueToFind, int startIndex)[source]¶
Finds the index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.- Since:
2.1
- public static int indexOf(double[] array, double valueToFind)[source]¶
Finds the index of the given value in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(double[] array, double valueToFind, double tolerance)[source]¶
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 anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
tolerance – tolerance of the search.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(double[] array, double valueToFind, int startIndex)[source]¶
Finds the index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(double[] array, double valueToFind, int startIndex, double tolerance)[source]¶
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 anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
tolerance – tolerance of the search.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(float[] array, float valueToFind)[source]¶
Finds the index of the given value in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(float[] array, float valueToFind, int startIndex)[source]¶
Finds the index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(int[] array, int valueToFind)[source]¶
Finds the index of the given value in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(int[] array, int valueToFind, int startIndex)[source]¶
Finds the index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(Object[] array, Object objectToFind)[source]¶
Finds the index of the given object in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
null.objectToFind – The object to find, may be
null.
- Returns:
The index of the object within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(Object[] array, Object objectToFind, int startIndex)[source]¶
Finds the index of the given object in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.objectToFind – The object to find, may be
null.startIndex – The index to start searching.
- Returns:
The index of the object within the array starting at the index,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(long[] array, long valueToFind)[source]¶
Finds the index of the given value in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(long[] array, long valueToFind, int startIndex)[source]¶
Finds the index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(short[] array, short valueToFind)[source]¶
Finds the index of the given value in the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to search for the object, may be
nullvalueToFind – The value to find.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int indexOf(short[] array, short valueToFind, int startIndex)[source]¶
Finds the index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return
#INDEX_NOT_FOUND(-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static BitSet indexesOf(boolean[] array, boolean valueToFind)[source]¶
Finds the indices of the given value in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(boolean[] array, boolean valueToFind, int startIndex)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet (
-1).- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(byte[] array, byte valueToFind)[source]¶
Finds the indices of the given value in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(byte[] array, byte valueToFind, int startIndex)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(char[] array, char valueToFind)[source]¶
Finds the indices of the given value in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(char[] array, char valueToFind, int startIndex)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(double[] array, double valueToFind)[source]¶
Finds the indices of the given value in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(double[] array, double valueToFind, double tolerance)[source]¶
Finds the indices of the given value within a given tolerance in the array.
This method will return all the indices of the value which fall between the region defined by valueToFind - tolerance and valueToFind + tolerance, each time between the nearest integers.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
tolerance – tolerance of the search.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(double[] array, double valueToFind, int startIndex)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
A BitSet of the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(double[] array, double valueToFind, int startIndex, double tolerance)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method will return the indices of the values which fall between the region defined by valueToFind - tolerance and valueToFind + tolerance, between the nearest integers.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
tolerance – tolerance of the search.
- Returns:
A BitSet of the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(float[] array, float valueToFind)[source]¶
Finds the indices of the given value in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(float[] array, float valueToFind, int startIndex)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(int[] array, int valueToFind)[source]¶
Finds the indices of the given value in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(int[] array, int valueToFind, int startIndex)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(Object[] array, Object objectToFind)[source]¶
Finds the indices of the given object in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.objectToFind – The object to find, may be
null.
- Returns:
A BitSet of all the indices of the object within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(Object[] array, Object objectToFind, int startIndex)[source]¶
Finds the indices of the given object in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.objectToFind – The object to find, may be
null.startIndex – The index to start searching.
- Returns:
A BitSet of all the indices of the object within the array starting at the index, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(long[] array, long valueToFind)[source]¶
Finds the indices of the given value in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(long[] array, long valueToFind, int startIndex)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(short[] array, short valueToFind)[source]¶
Finds the indices of the given value in the array.
This method returns an empty BitSet for a
nullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static BitSet indexesOf(short[] array, short valueToFind, int startIndex)[source]¶
Finds the indices of the given value in the array starting at the given index.
This method returns an empty BitSet for a
nullinput array.A negative startIndex is treated as zero. A startIndex larger than the array length will return an empty BitSet.
- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
startIndex – The index to start searching.
- Returns:
A BitSet of all the indices of the value within the array, an empty BitSet if not found or
nullarray input.- Since:
3.10
- public static boolean[] insert(int index, boolean[] array, boolean... values)[source]¶
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
- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- public static byte[] insert(int index, byte[] array, byte... values)[source]¶
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
- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- public static char[] insert(int index, char[] array, char... values)[source]¶
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
- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- public static double[] insert(int index, double[] array, double... values)[source]¶
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
- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- public static float[] insert(int index, float[] array, float... values)[source]¶
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
- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- public static int[] insert(int index, int[] array, int... values)[source]¶
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
- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- @SafeVarargs public static <T> T[] insert(int index, T[] array, T... values)[source]¶
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
- Type parameters:
<T> – The type of elements in
arrayandvalues.- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- public static long[] insert(int index, long[] array, long... values)[source]¶
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
- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- public static short[] insert(int index, short[] array, short... values)[source]¶
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
- Parameters:
index – The position within
arrayto insert the new values.array – The array to insert the values into, may be
null.values – The new values to insert, may be
null.
- Returns:
The new array or
nullif the given array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if
arrayis provided and eitherindex < 0orindex > array.length.java.lang.IllegalArgumentException – Thrown if the total array length exceeds
ArrayUtils#SAFE_MAX_ARRAY_LENGTH.
- Since:
3.6
- public static <T> boolean isArrayIndexValid(T[] array, int index)[source]¶
Tests whether a given array can safely be accessed at the given index.
ArrayUtils.isArrayIndexValid(null, 0) = false ArrayUtils.isArrayIndexValid([], 0) = false ArrayUtils.isArrayIndexValid(["a"], 0) = true
- Type parameters:
<T> – The component type of the array.
- Parameters:
array – The array to inspect, may be
null.index – The index of the array to be inspected.
- Returns:
Whether the given index is safely-accessible in the given array.
- Since:
3.8
- public static boolean isEmpty(boolean[] array)[source]¶
Tests whether an array of primitive booleans is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- public static boolean isEmpty(byte[] array)[source]¶
Tests whether an array of primitive bytes is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- public static boolean isEmpty(char[] array)[source]¶
Tests whether an array of primitive chars is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- public static boolean isEmpty(double[] array)[source]¶
Tests whether an array of primitive doubles is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- public static boolean isEmpty(float[] array)[source]¶
Tests whether an array of primitive floats is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- public static boolean isEmpty(int[] array)[source]¶
Tests whether an array of primitive ints is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- public static boolean isEmpty(Object[] array)[source]¶
Tests whether an array of Objects is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- public static boolean isEmpty(long[] array)[source]¶
Tests whether an array of primitive longs is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- public static boolean isEmpty(short[] array)[source]¶
Tests whether an array of primitive shorts is empty or
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is empty ornull.- Since:
2.1
- @Deprecated public static boolean isEquals(Object array1, Object array2)[source]¶
Deprecated: Replaced by
java.util.Objects.deepEquals(Object, Object)and will be removed from future releases.Tests whether two arrays have equal content, using equals(), handling multidimensional arrays correctly.
Multi-dimensional primitive arrays are also handled correctly by this method.
- Parameters:
array1 – The left-hand side array to compare, may be
null.array2 – The right-hand side array to compare, may be
null.
- Returns:
trueif the arrays are equal.
- public static boolean isNotEmpty(boolean[] array)[source]¶
Tests whether an array of primitive booleans is not empty and not
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static boolean isNotEmpty(byte[] array)[source]¶
Tests whether an array of primitive bytes is not empty and not
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static boolean isNotEmpty(char[] array)[source]¶
Tests whether an array of primitive chars is not empty and not
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static boolean isNotEmpty(double[] array)[source]¶
Tests whether an array of primitive doubles is not empty and not
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static boolean isNotEmpty(float[] array)[source]¶
Tests whether an array of primitive floats is not empty and not
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static boolean isNotEmpty(int[] array)[source]¶
Tests whether an array of primitive ints is not empty and not
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static <T> boolean isNotEmpty(T[] array)[source]¶
Tests whether an array of Objects is not empty and not
null.- Type parameters:
<T> – The component type of the array
- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static boolean isNotEmpty(long[] array)[source]¶
Tests whether an array of primitive longs is not empty and not
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static boolean isNotEmpty(short[] array)[source]¶
Tests whether an array of primitive shorts is not empty and not
null.- Parameters:
array – The array to test.
- Returns:
trueif the array is not empty and notnull.- Since:
2.5
- public static boolean isSameLength(boolean[] array1, boolean[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameLength(byte[] array1, byte[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameLength(char[] array1, char[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameLength(double[] array1, double[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameLength(float[] array1, float[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameLength(int[] array1, int[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameLength(Object array1, Object array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.Any multi-dimensional aspects of the arrays are ignored.
- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.- Since:
3.11
- public static boolean isSameLength(Object[] array1, Object[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.Any multi-dimensional aspects of the arrays are ignored.
- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameLength(long[] array1, long[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameLength(short[] array1, short[] array2)[source]¶
Tests whether two arrays are the same length, treating
nullarrays as length0.- Parameters:
array1 – The first array, may be
null.array2 – The second array, may be
null.
- Returns:
trueif length of arrays matches, treatingnullas an empty array.
- public static boolean isSameType(Object array1, Object array2)[source]¶
Tests whether two arrays are the same type taking into account multidimensional arrays.
- Parameters:
array1 – The first array, must not be
null.array2 – The second array, must not be
null.
- Returns:
trueif type of arrays matches.- Throws:
java.lang.IllegalArgumentException – Thrown if either array is
null.
- public static boolean isSorted(boolean[] array)[source]¶
Tests whether the provided array is sorted according to natural ordering (
falsebeforetrue).- Parameters:
array – The array to check.
- Returns:
whether the array is sorted according to natural ordering.
- Since:
3.4
- public static boolean isSorted(byte[] array)[source]¶
Tests whether the provided array is sorted according to natural ordering.
- Parameters:
array – The array to check.
- Returns:
whether the array is sorted according to natural ordering.
- Since:
3.4
- public static boolean isSorted(char[] array)[source]¶
Tests whether the provided array is sorted according to natural ordering.
- Parameters:
array – The array to check.
- Returns:
whether the array is sorted according to natural ordering.
- Since:
3.4
- public static boolean isSorted(double[] array)[source]¶
Tests whether the provided array is sorted according to natural ordering.
- Parameters:
array – The array to check.
- Returns:
whether the array is sorted according to natural ordering.
- Since:
3.4
- public static boolean isSorted(float[] array)[source]¶
Tests whether the provided array is sorted according to natural ordering.
- Parameters:
array – The array to check.
- Returns:
whether the array is sorted according to natural ordering.
- Since:
3.4
- public static boolean isSorted(int[] array)[source]¶
Tests whether the provided array is sorted according to natural ordering.
- Parameters:
array – The array to check.
- Returns:
whether the array is sorted according to natural ordering.
- Since:
3.4
- public static <T extends Comparable<? super T>> boolean isSorted(T[] array)[source]¶
Tests whether the provided array is sorted according to the class’s
compareTomethod.- Parameters:
array – The array to check.
- Type parameters:
<T> – The datatype of the array to check, it must implement
Comparable.- Returns:
whether the array is sorted.
- Since:
3.4
- public static <T> boolean isSorted(T[] array, Comparator<T> comparator)[source]¶
Tests whether the provided array is sorted according to the provided
Comparator.- Parameters:
array – The array to check.
comparator – The
Comparatorto compare over.
- Type parameters:
<T> – The datatype of the array.
- Returns:
whether the array is sorted.
- Throws:
java.lang.NullPointerException – Thrown if
comparatorisnull.- Since:
3.4
- public static boolean isSorted(long[] array)[source]¶
Tests whether the provided array is sorted according to natural ordering.
- Parameters:
array – The array to check.
- Returns:
whether the array is sorted according to natural ordering.
- Since:
3.4
- public static boolean isSorted(short[] array)[source]¶
Tests whether the provided array is sorted according to natural ordering.
- Parameters:
array – The array to check.
- Returns:
whether the array is sorted according to natural ordering.
- Since:
3.4
- public static int lastIndexOf(boolean[] array, boolean valueToFind)[source]¶
Finds the last index of the given value within the array.
This method returns
#INDEX_NOT_FOUND(-1) ifnullarray input.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.valueToFind – The object to find.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(boolean[] array, boolean valueToFind, int startIndex)[source]¶
Finds the last index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(byte[] array, byte valueToFind)[source]¶
Finds the last index of the given value within the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.valueToFind – The object to find.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(byte[] array, byte valueToFind, int startIndex)[source]¶
Finds the last index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(char[] array, char valueToFind)[source]¶
Finds the last index of the given value within the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.valueToFind – The object to find.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.- Since:
2.1
- public static int lastIndexOf(char[] array, char valueToFind, int startIndex)[source]¶
Finds the last index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.- Since:
2.1
- public static int lastIndexOf(double[] array, double valueToFind)[source]¶
Finds the last index of the given value within the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.valueToFind – The object to find.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(double[] array, double valueToFind, double tolerance)[source]¶
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 anullinput array.- Parameters:
array – The array to search for the object, may be
null.valueToFind – The value to find.
tolerance – tolerance of the search.
- Returns:
The index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(double[] array, double valueToFind, int startIndex)[source]¶
Finds the last index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(double[] array, double valueToFind, int startIndex, double tolerance)[source]¶
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 anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
tolerance – search for value within plus/minus this amount.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(float[] array, float valueToFind)[source]¶
Finds the last index of the given value within the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.valueToFind – The object to find.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(float[] array, float valueToFind, int startIndex)[source]¶
Finds the last index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(int[] array, int valueToFind)[source]¶
Finds the last index of the given value within the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.valueToFind – The object to find.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(int[] array, int valueToFind, int startIndex)[source]¶
Finds the last index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(Object[] array, Object objectToFind)[source]¶
Finds the last index of the given object within the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.objectToFind – The object to find, may be
null.
- Returns:
The last index of the object within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(Object[] array, Object objectToFind, int startIndex)[source]¶
Finds the last index of the given object in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
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 from.
- Returns:
The last index of the object within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(long[] array, long valueToFind)[source]¶
Finds the last index of the given value within the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.valueToFind – The object to find.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(long[] array, long valueToFind, int startIndex)[source]¶
Finds the last index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(short[] array, short valueToFind)[source]¶
Finds the last index of the given value within the array.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput array.- Parameters:
array – The array to traverse backwards looking for the object, may be
null.valueToFind – The object to find.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- public static int lastIndexOf(short[] array, short valueToFind, int startIndex)[source]¶
Finds the last index of the given value in the array starting at the given index.
This method returns
#INDEX_NOT_FOUND(-1) for anullinput 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.- Parameters:
array – The array to traverse for looking for the object, may be
null.valueToFind – The value to find.
startIndex – The start index to traverse backwards from.
- Returns:
The last index of the value within the array,
#INDEX_NOT_FOUND(-1) if not found ornullarray input.
- @SuppressWarnings({"unchecked"}) public static <T> T[] newInstance(Class<T> componentType, int length)[source]¶
Delegates to
Array#newInstance(Class,int)using generics.- Type parameters:
<T> – The array type.
- Parameters:
componentType – The array class.
length – The array length
- Returns:
The new array.
- Throws:
java.lang.NullPointerException – Thrown if the specified
componentTypeparameter is null.- Since:
3.13.0
- public static <T> T[] nullTo(T[] array, T[] defaultArray)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns a default array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Type parameters:
<T> – The array type.
- Parameters:
array – The array to check for
nullor emptydefaultArray – A default array, usually empty.
- Returns:
The same array, or defaultArray if
nullor empty input.- Since:
3.15.0
- public static boolean[] nullToEmpty(boolean[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static byte[] nullToEmpty(byte[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static char[] nullToEmpty(char[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static double[] nullToEmpty(double[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static float[] nullToEmpty(float[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static int[] nullToEmpty(int[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static Boolean[] nullToEmpty(Boolean[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static Byte[] nullToEmpty(Byte[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static Character[] nullToEmpty(Character[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static Class<?>[] nullToEmpty(Class<?>[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
3.2
- public static Double[] nullToEmpty(Double[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static Float[] nullToEmpty(Float[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static Integer[] nullToEmpty(Integer[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static Long[] nullToEmpty(Long[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static Object[] nullToEmpty(Object[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static <T> T[] nullToEmpty(T[] array, Class<T[]> type)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.- Parameters:
array – The array to check for
nullor empty.type – The class representation of the desired array.
- Type parameters:
<T> – the class type.
- Returns:
The same array,
public staticempty array ifnull.- Throws:
java.lang.IllegalArgumentException – Thrown if the type argument is null.
- Since:
3.5
- public static Short[] nullToEmpty(Short[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static String[] nullToEmpty(String[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static long[] nullToEmpty(long[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static short[] nullToEmpty(short[] array)[source]¶
Defensive programming technique to change a
nullreference to an empty one.This method returns an empty array for a
nullinput array.As a memory optimizing technique an empty array passed in will be overridden with the empty
public staticreferences in this class.- Parameters:
array – The array to check for
nullor empty.- Returns:
The same array,
public staticempty array ifnullor empty input.- Since:
2.5
- public static boolean[] remove(boolean[] array, int index)[source]¶
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]
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- public static byte[] remove(byte[] array, int index)[source]¶
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]
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- public static char[] remove(char[] array, int index)[source]¶
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']
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- public static double[] remove(double[] array, int index)[source]¶
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]
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- public static float[] remove(float[] array, int index)[source]¶
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]
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- public static int[] remove(int[] array, int index)[source]¶
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]
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- @SuppressWarnings({"unchecked"}) public static <T> T[] remove(T[] array, int index)[source]¶
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"]
- Type parameters:
<T> – the component type of the array.
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- public static long[] remove(long[] array, int index)[source]¶
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]
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- public static short[] remove(short[] array, int index)[source]¶
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]
- Parameters:
array – The array to remove the element from, may not be
null.index – The position of the element to be removed.
- Returns:
A new array containing the existing elements except the element at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException – Thrown if the index is out of range (index < 0 || index >= array.length), or if the array is
null.- Since:
2.1
- public static boolean[] removeAll(boolean[] array, int... indices)[source]¶
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, then returnnull.ArrayUtils.removeAll([true, false, true], 0, 2) = [false] ArrayUtils.removeAll([true, false, true], 1, 2) = [true]
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- public static byte[] removeAll(byte[] array, int... indices)[source]¶
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, then returnnull.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) = []
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- public static char[] removeAll(char[] array, int... indices)[source]¶
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, then returnnull.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) = []
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- public static double[] removeAll(double[] array, int... indices)[source]¶
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, then returnnull.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) = []
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- public static float[] removeAll(float[] array, int... indices)[source]¶
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, then returnnull.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) = []
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- public static int[] removeAll(int[] array, int... indices)[source]¶
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, then returnnull.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) = []
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- @SuppressWarnings({"unchecked"}) public static <T> T[] removeAll(T[] array, int... indices)[source]¶
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, then returnnull.ArrayUtils.removeAll(["a", "b", "c"], 0, 2) = ["b"] ArrayUtils.removeAll(["a", "b", "c"], 1, 2) = ["a"]
- Type parameters:
<T> – the component type of the array.
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- public static long[] removeAll(long[] array, int... indices)[source]¶
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, then returnnull.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) = []
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- public static short[] removeAll(short[] array, int... indices)[source]¶
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, then returnnull.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) = []
- Parameters:
array – The array to remove the element from, may not be
null.indices – The positions of the elements to be removed.
- Returns:
A new array containing the existing elements except those at the specified positions or
nullif the input array isnull.- Throws:
java.lang.IndexOutOfBoundsException – Thrown if any index is out of range (index < 0 || index >= array.length).
- Since:
3.0.1
- @Deprecated public static boolean[] removeAllOccurences(boolean[] array, boolean element)[source]¶
Deprecated: Use
#removeAllOccurrences(boolean[], boolean).Removes the occurrences of the specified element from the specified boolean array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- @Deprecated public static byte[] removeAllOccurences(byte[] array, byte element)[source]¶
Deprecated: Use
#removeAllOccurrences(byte[], byte).Removes the occurrences of the specified element from the specified byte array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- @Deprecated public static char[] removeAllOccurences(char[] array, char element)[source]¶
Deprecated: Use
#removeAllOccurrences(char[], char).Removes the occurrences of the specified element from the specified char array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- @Deprecated public static double[] removeAllOccurences(double[] array, double element)[source]¶
Deprecated: Use
#removeAllOccurrences(double[], double).Removes the occurrences of the specified element from the specified double array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- @Deprecated public static float[] removeAllOccurences(float[] array, float element)[source]¶
Deprecated: Use
#removeAllOccurrences(float[], float).Removes the occurrences of the specified element from the specified float array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- @Deprecated public static int[] removeAllOccurences(int[] array, int element)[source]¶
Deprecated: Use
#removeAllOccurrences(int[], int).Removes the occurrences of the specified element from the specified int array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- @Deprecated public static <T> T[] removeAllOccurences(T[] array, T element)[source]¶
Deprecated: Use
#removeAllOccurrences(Object[], Object).Removes the occurrences 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 contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Type parameters:
<T> – The type of object in the array, may be
null.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove, may be
null.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- @Deprecated public static long[] removeAllOccurences(long[] array, long element)[source]¶
Deprecated: Use
#removeAllOccurrences(long[], long).Removes the occurrences of the specified element from the specified long array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- @Deprecated public static short[] removeAllOccurences(short[] array, short element)[source]¶
Deprecated: Use
#removeAllOccurrences(short[], short).Removes the occurrences of the specified element from the specified short array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.5
- public static boolean[] removeAllOccurrences(boolean[] array, boolean element)[source]¶
Removes the occurrences of the specified element from the specified boolean array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static byte[] removeAllOccurrences(byte[] array, byte element)[source]¶
Removes the occurrences of the specified element from the specified byte array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static char[] removeAllOccurrences(char[] array, char element)[source]¶
Removes the occurrences of the specified element from the specified char array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static double[] removeAllOccurrences(double[] array, double element)[source]¶
Removes the occurrences of the specified element from the specified double array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static float[] removeAllOccurrences(float[] array, float element)[source]¶
Removes the occurrences of the specified element from the specified float array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static int[] removeAllOccurrences(int[] array, int element)[source]¶
Removes the occurrences of the specified element from the specified int array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static <T> T[] removeAllOccurrences(T[] array, T element)[source]¶
Removes the occurrences 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 contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Type parameters:
<T> – The type of object in the array, may be
null.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove, may be
null.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static long[] removeAllOccurrences(long[] array, long element)[source]¶
Removes the occurrences of the specified element from the specified long array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static short[] removeAllOccurrences(short[] array, short element)[source]¶
Removes the occurrences of the specified element from the specified short array.
All subsequent elements are shifted to the left (subtracts one from their indices). If the array doesn’t contain such an element, no elements are removed from the array.
nullwill be returned if the input array isnull.- Parameters:
array – The input array, will not be modified, and may be
null.element – The element to remove.
- Returns:
A new array containing the existing elements except the occurrences of the specified element.
- Since:
3.10
- public static boolean[] removeElement(boolean[] array, boolean element)[source]¶
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 contain 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]
- Parameters:
array – The input array, may be
null.element – The element to be removed.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static byte[] removeElement(byte[] array, byte element)[source]¶
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 contain 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]
- Parameters:
array – The input array, may be
null.element – The element to be removed.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static char[] removeElement(char[] array, char element)[source]¶
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 contain 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']
- Parameters:
array – The input array, may be
null.element – The element to be removed.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static double[] removeElement(double[] array, double element)[source]¶
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 contain 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]
- Parameters:
array – The input array, may be
null.element – The element to be removed.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static float[] removeElement(float[] array, float element)[source]¶
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 contain 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]
- Parameters:
array – The input array, may be
null.element – The element to be removed.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static int[] removeElement(int[] array, int element)[source]¶
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 contain 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]
- Parameters:
array – The input array, may be
null.element – The element to be removed.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static <T> T[] removeElement(T[] array, Object element)[source]¶
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 contain 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"]
- Type parameters:
<T> – The component type of the array
- Parameters:
array – The input array, may be
null.element – The element to be removed, may be
null.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static long[] removeElement(long[] array, long element)[source]¶
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 contain 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]
- Parameters:
array – The input array, may be
null.element – The element to be removed.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static short[] removeElement(short[] array, short element)[source]¶
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 contain 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]
- Parameters:
array – The input array, may be
null.element – The element to be removed.
- Returns:
A new array containing the existing elements except the first occurrence of the specified element.
- Since:
2.1
- public static boolean[] removeElements(boolean[] array, boolean... values)[source]¶
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]
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- public static byte[] removeElements(byte[] array, byte... values)[source]¶
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]
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- public static char[] removeElements(char[] array, char... values)[source]¶
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]
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- public static double[] removeElements(double[] array, double... values)[source]¶
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]
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- public static float[] removeElements(float[] array, float... values)[source]¶
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]
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- public static int[] removeElements(int[] array, int... values)[source]¶
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]
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- @SafeVarargs public static <T> T[] removeElements(T[] array, T... values)[source]¶
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"]
- Type parameters:
<T> – The component type of the array
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- public static long[] removeElements(long[] array, long... values)[source]¶
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]
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- public static short[] removeElements(short[] array, short... values)[source]¶
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]
- Parameters:
array – The input array, will not be modified, and may be
null.values – The values to be removed.
- Returns:
A new array containing the existing elements except the earliest-encountered occurrences of the specified elements.
- Since:
3.0.1
- public static void reverse(boolean[] array)[source]¶
Reverses the order of the given array.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null.
- public static void reverse(boolean[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static void reverse(byte[] array)[source]¶
Reverses the order of the given array.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null.
- public static void reverse(byte[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static void reverse(char[] array)[source]¶
Reverses the order of the given array.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null.
- public static void reverse(char[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static void reverse(double[] array)[source]¶
Reverses the order of the given array.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null
- public static void reverse(double[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static void reverse(float[] array)[source]¶
Reverses the order of the given array.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null.
- public static void reverse(float[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static void reverse(int[] array)[source]¶
Reverses the order of the given array.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null.
- public static void reverse(int[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static void reverse(Object[] array)[source]¶
Reverses the order of the given array.
There is no special handling for multi-dimensional arrays.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null.
- public static void reverse(Object[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static void reverse(long[] array)[source]¶
Reverses the order of the given array.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null.
- public static void reverse(long[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static void reverse(short[] array)[source]¶
Reverses the order of the given array.
This method does nothing for a
nullinput array.- Parameters:
array – The array to reverse, may be
null.
- public static void reverse(short[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Reverses the order of the given array in the given range.
This method does nothing for a
nullinput array.- Parameters:
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.
- Since:
3.2
- public static <T> T[] setAll(T[] array, IntFunction<? extends T> generator)[source]¶
Sets all elements of the specified array, using the provided generator supplier to compute each element.
If the generator supplier throws an exception, it is relayed to the caller and the array is left in an indeterminate state.
- Type parameters:
<T> – type of elements of the array, may be
null.- Parameters:
array – array to be initialized, may be
null.generator – A function accepting an index and producing the desired value for that position.
- Returns:
The input array
- Since:
3.13.0
- public static <T> T[] setAll(T[] array, Supplier<? extends T> generator)[source]¶
Sets all elements of the specified array, using the provided generator supplier to compute each element.
If the generator supplier throws an exception, it is relayed to the caller and the array is left in an indeterminate state.
- Type parameters:
<T> – type of elements of the array, may be
null.- Parameters:
array – array to be initialized, may be
null.generator – A function accepting an index and producing the desired value for that position.
- Returns:
The input array
- Since:
3.13.0
- public static void shift(boolean[] array, int offset)[source]¶
Shifts the order of the given boolean array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(boolean[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given boolean array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(byte[] array, int offset)[source]¶
Shifts the order of the given byte array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(byte[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given byte array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(char[] array, int offset)[source]¶
Shifts the order of the given char array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(char[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given char array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(double[] array, int offset)[source]¶
Shifts the order of the given double array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(double[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given double array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(float[] array, int offset)[source]¶
Shifts the order of the given float array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(float[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given float array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(int[] array, int offset)[source]¶
Shifts the order of the given int array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(int[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given int array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(Object[] array, int offset)[source]¶
Shifts the order of the given array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(Object[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(long[] array, int offset)[source]¶
Shifts the order of the given long array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(long[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given long array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(short[] array, int offset)[source]¶
Shifts the order of the given short array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shift(short[] array, int startIndexInclusive, int endIndexExclusive, int offset)[source]¶
Shifts the order of a series of elements in the given short array.
There is no special handling for multi-dimensional arrays. This method does nothing for
nullor empty input arrays.- Parameters:
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.
- Since:
3.5
- public static void shuffle(boolean[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(boolean[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static void shuffle(byte[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(byte[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static void shuffle(char[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(char[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static void shuffle(double[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(double[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static void shuffle(float[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(float[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static void shuffle(int[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(int[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static void shuffle(Object[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(Object[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static void shuffle(long[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(long[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static void shuffle(short[] array)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
This method uses the current
ThreadLocalRandomas its random number generator.Instances of
ThreadLocalRandomare not cryptographically secure. For security-sensitive applications, consider using ashufflemethod with aSecureRandomargument.- Parameters:
array – The array to shuffle.
- See also:
- Since:
3.6
- public static void shuffle(short[] array, Random random)[source]¶
Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.
- Parameters:
array – The array to shuffle, no-op if
null.random – The source of randomness used to permute the elements, no-op if
null.
- See also:
- Since:
3.6
- public static boolean startsWith(byte[] data, byte[] expected)[source]¶
Tests whether the given data array starts with an expected array, for example, signature bytes.
If both arrays are null, the method returns true. The method return false when one array is null and the other not.
- Parameters:
data – The data to search, maybe larger than the expected data.
expected – The expected data to find.
- Returns:
whether a match was found.
- Since:
3.18.0
- public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Produces a new
booleanarray containing the elements between the start and end indices.The start index is inclusive, the end index exclusive. Null array input produces null output.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static byte[] subarray(byte[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Produces a new
bytearray containing the elements between the start and end indices.The start index is inclusive, the end index exclusive. Null array input produces null output.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static char[] subarray(char[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Produces a new
chararray containing the elements between the start and end indices.The start index is inclusive, the end index exclusive. Null array input produces null output.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static double[] subarray(double[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Produces a new
doublearray containing the elements between the start and end indices.The start index is inclusive, the end index exclusive. Null array input produces null output.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static float[] subarray(float[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Produces a new
floatarray containing the elements between the start and end indices.The start index is inclusive, the end index exclusive. Null array input produces null output.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static int[] subarray(int[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Produces a new
intarray containing the elements between the start and end indices.The start index is inclusive, the end index exclusive. Null array input produces null output.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static <T> T[] subarray(T[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
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);
- Type parameters:
<T> – the component type of the array.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static long[] subarray(long[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Produces a new
longarray containing the elements between the start and end indices.The start index is inclusive, the end index exclusive. Null array input produces null output.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static short[] subarray(short[] array, int startIndexInclusive, int endIndexExclusive)[source]¶
Produces a new
shortarray containing the elements between the start and end indices.The start index is inclusive, the end index exclusive. Null array input produces null output.
- Parameters:
array – The input array.
startIndexInclusive – 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.
- Returns:
A new array containing the elements between the start and end indices.
- Since:
2.1
- See also:
- public static void swap(boolean[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given boolean array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]
ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]
ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(boolean[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given boolean array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([true, false, true, false], 0, 2, 1) -> [true, false, true, false]
ArrayUtils.swap([true, false, true, false], 0, 0, 1) -> [true, false, true, false]
ArrayUtils.swap([true, false, true, false], 0, 2, 2) -> [true, false, true, false]
ArrayUtils.swap([true, false, true, false], -3, 2, 2) -> [true, false, true, false]
ArrayUtils.swap([true, false, true, false], 0, 3, 3) -> [false, false, true, true]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static void swap(byte[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given byte array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]
ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]
ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(byte[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given byte array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([1, 2, 3, 4], 0, 2, 1) -> [3, 2, 1, 4]
ArrayUtils.swap([1, 2, 3, 4], 0, 0, 1) -> [1, 2, 3, 4]
ArrayUtils.swap([1, 2, 3, 4], 2, 0, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], -3, 2, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], 0, 3, 3) -> [4, 2, 3, 1]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static void swap(char[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given char array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]
ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]
ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(char[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given char array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([1, 2, 3, 4], 0, 2, 1) -> [3, 2, 1, 4]
ArrayUtils.swap([1, 2, 3, 4], 0, 0, 1) -> [1, 2, 3, 4]
ArrayUtils.swap([1, 2, 3, 4], 2, 0, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], -3, 2, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], 0, 3, 3) -> [4, 2, 3, 1]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static void swap(double[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given double array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]
ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]
ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(double[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given double array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([1, 2, 3, 4], 0, 2, 1) -> [3, 2, 1, 4]
ArrayUtils.swap([1, 2, 3, 4], 0, 0, 1) -> [1, 2, 3, 4]
ArrayUtils.swap([1, 2, 3, 4], 2, 0, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], -3, 2, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], 0, 3, 3) -> [4, 2, 3, 1]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static void swap(float[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given float array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]
ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]
ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(float[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given float array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([1, 2, 3, 4], 0, 2, 1) -> [3, 2, 1, 4]
ArrayUtils.swap([1, 2, 3, 4], 0, 0, 1) -> [1, 2, 3, 4]
ArrayUtils.swap([1, 2, 3, 4], 2, 0, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], -3, 2, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], 0, 3, 3) -> [4, 2, 3, 1]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static void swap(int[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given int array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]
ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]
ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(int[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given int array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([1, 2, 3, 4], 0, 2, 1) -> [3, 2, 1, 4]
ArrayUtils.swap([1, 2, 3, 4], 0, 0, 1) -> [1, 2, 3, 4]
ArrayUtils.swap([1, 2, 3, 4], 2, 0, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], -3, 2, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], 0, 3, 3) -> [4, 2, 3, 1]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static void swap(Object[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([“1”, “2”, “3”], 0, 2) -> [“3”, “2”, “1”]
ArrayUtils.swap([“1”, “2”, “3”], 0, 0) -> [“1”, “2”, “3”]
ArrayUtils.swap([“1”, “2”, “3”], 1, 0) -> [“2”, “1”, “3”]
ArrayUtils.swap([“1”, “2”, “3”], 0, 5) -> [“1”, “2”, “3”]
ArrayUtils.swap([“1”, “2”, “3”], -1, 1) -> [“2”, “1”, “3”]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(Object[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([“1”, “2”, “3”, “4”], 0, 2, 1) -> [“3”, “2”, “1”, “4”]
ArrayUtils.swap([“1”, “2”, “3”, “4”], 0, 0, 1) -> [“1”, “2”, “3”, “4”]
ArrayUtils.swap([“1”, “2”, “3”, “4”], 2, 0, 2) -> [“3”, “4”, “1”, “2”]
ArrayUtils.swap([“1”, “2”, “3”, “4”], -3, 2, 2) -> [“3”, “4”, “1”, “2”]
ArrayUtils.swap([“1”, “2”, “3”, “4”], 0, 3, 3) -> [“4”, “2”, “3”, “1”]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static void swap(long[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given long array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([true, false, true], 0, 2) -> [true, false, true]
ArrayUtils.swap([true, false, true], 0, 0) -> [true, false, true]
ArrayUtils.swap([true, false, true], 1, 0) -> [false, true, true]
ArrayUtils.swap([true, false, true], 0, 5) -> [true, false, true]
ArrayUtils.swap([true, false, true], -1, 1) -> [false, true, true]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(long[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given long array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([1, 2, 3, 4], 0, 2, 1) -> [3, 2, 1, 4]
ArrayUtils.swap([1, 2, 3, 4], 0, 0, 1) -> [1, 2, 3, 4]
ArrayUtils.swap([1, 2, 3, 4], 2, 0, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], -3, 2, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], 0, 3, 3) -> [4, 2, 3, 1]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static void swap(short[] array, int offset1, int offset2)[source]¶
Swaps two elements in the given short array.
There is no special handling for multi-dimensional arrays. This method does nothing for a
nullor empty input array or for overflow indices. Negative indices are promoted to 0(zero).Examples:
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]
ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]
ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element to swap.
offset2 – The index of the second element to swap.
- Since:
3.5
- public static void swap(short[] array, int offset1, int offset2, int len)[source]¶
Swaps a series of elements in the given short array.
This method does nothing for a
nullor 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.Examples:
ArrayUtils.swap([1, 2, 3, 4], 0, 2, 1) -> [3, 2, 1, 4]
ArrayUtils.swap([1, 2, 3, 4], 0, 0, 1) -> [1, 2, 3, 4]
ArrayUtils.swap([1, 2, 3, 4], 2, 0, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], -3, 2, 2) -> [3, 4, 1, 2]
ArrayUtils.swap([1, 2, 3, 4], 0, 3, 3) -> [4, 2, 3, 1]
- Parameters:
array – The array to swap, may be
null.offset1 – The index of the first element in the series to swap.
offset2 – The index of the second element in the series to swap.
len – The number of elements to swap starting with the given indices.
- Since:
3.5
- public static <T> T[] toArray(@SuppressWarnings({"unchecked"}) T... items)[source]¶
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 tonew Number[] {Integer.valueOf(42), Double.valueOf(Math.PI)}.- Type parameters:
<T> – the array’s element type.
- Parameters:
items – the varargs array items, null allowed.
- Returns:
The array, not null unless a null array is passed in.
- Since:
3.0
- public static Map<Object, Object> toMap(Object[] array)[source]¶
Converts the given array into a
java.util.Map. Each element of the array must be either ajava.util.Map.Entryor 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
nullfor anullinput array.- Parameters:
array – An array whose elements are either a
java.util.Map.Entryor an Array containing at least two elements, may benull.- Returns:
A
Mapthat was created from the array.- Throws:
java.lang.IllegalArgumentException – Thrown if one element of this Array is itself an Array containing less than two elements.
Thrown if the array contains elements other than
java.util.Map.Entryand an Array.
- public static Boolean[] toObject(boolean[] array)[source]¶
Converts an array of primitive booleans to objects.
This method returns
nullfor anullinput array.- Parameters:
array – A
booleanarray.- Returns:
A
Booleanarray,nullif null array input.
- public static Byte[] toObject(byte[] array)[source]¶
Converts an array of primitive bytes to objects.
This method returns
nullfor anullinput array.- Parameters:
array – A
bytearray.- Returns:
A
Bytearray,nullif null array input.
- public static Character[] toObject(char[] array)[source]¶
Converts an array of primitive chars to objects.
This method returns
nullfor anullinput array.- Parameters:
array – A
chararray.- Returns:
A
Characterarray,nullif null array input.
- public static Double[] toObject(double[] array)[source]¶
Converts an array of primitive doubles to objects.
This method returns
nullfor anullinput array.- Parameters:
array – A
doublearray.- Returns:
A
Doublearray,nullif null array input.
- public static Float[] toObject(float[] array)[source]¶
Converts an array of primitive floats to objects.
This method returns
nullfor anullinput array.- Parameters:
array – A
floatarray.- Returns:
A
Floatarray,nullif null array input.
- public static Integer[] toObject(int[] array)[source]¶
Converts an array of primitive ints to objects.
This method returns
nullfor anullinput array.- Parameters:
array – An
intarray.- Returns:
An
Integerarray,nullif null array input.
- public static Long[] toObject(long[] array)[source]¶
Converts an array of primitive longs to objects.
This method returns
nullfor anullinput array.- Parameters:
array – A
longarray.- Returns:
A
Longarray,nullif null array input.
- public static Short[] toObject(short[] array)[source]¶
Converts an array of primitive shorts to objects.
This method returns
nullfor anullinput array.- Parameters:
array – A
shortarray.- Returns:
A
Shortarray,nullif null array input.
- public static boolean[] toPrimitive(Boolean[] array)[source]¶
Converts an array of object Booleans to primitives.
This method returns
nullfor anullinput array.Null array elements map to false, like
Boolean.parseBoolean(null)and its callers return false.- Parameters:
array – A
Booleanarray, may benull.- Returns:
A
booleanarray,nullif null array input.
- public static boolean[] toPrimitive(Boolean[] array, boolean valueForNull)[source]¶
Converts an array of object Booleans to primitives handling
null.This method returns
nullfor anullinput array.- Parameters:
array – A
Booleanarray, may benull.valueForNull – The value to insert if
nullfound.
- Returns:
A
booleanarray,nullif null array input.
- public static byte[] toPrimitive(Byte[] array)[source]¶
Converts an array of object Bytes to primitives.
This method returns
nullfor anullinput array.- Parameters:
array – A
Bytearray, may benull.- Returns:
A
bytearray,nullif null array input.- Throws:
java.lang.NullPointerException – Thrown if an array element is
null.
- public static byte[] toPrimitive(Byte[] array, byte valueForNull)[source]¶
Converts an array of object Bytes to primitives handling
null.This method returns
nullfor anullinput array.- Parameters:
array – A
Bytearray, may benull.valueForNull – The value to insert if
nullfound.
- Returns:
A
bytearray,nullif null array input.
- public static char[] toPrimitive(Character[] array)[source]¶
Converts an array of object Characters to primitives.
This method returns
nullfor anullinput array.- Parameters:
array – A
Characterarray, may benull.- Returns:
A
chararray,nullif null array input.- Throws:
java.lang.NullPointerException – Thrown if an array element is
null.
- public static char[] toPrimitive(Character[] array, char valueForNull)[source]¶
Converts an array of object Character to primitives handling
null.This method returns
nullfor anullinput array.- Parameters:
array – A
Characterarray, may benull.valueForNull – The value to insert if
nullfound.
- Returns:
A
chararray,nullif null array input.
- public static double[] toPrimitive(Double[] array)[source]¶
Converts an array of object Doubles to primitives.
This method returns
nullfor anullinput array.- Parameters:
array – A
Doublearray, may benull.- Returns:
A
doublearray,nullif null array input.- Throws:
java.lang.NullPointerException – Thrown if an array element is
null.
- public static double[] toPrimitive(Double[] array, double valueForNull)[source]¶
Converts an array of object Doubles to primitives handling
null.This method returns
nullfor anullinput array.- Parameters:
array – A
Doublearray, may benull.valueForNull – The value to insert if
nullfound.
- Returns:
A
doublearray,nullif null array input.
- public static float[] toPrimitive(Float[] array)[source]¶
Converts an array of object Floats to primitives.
This method returns
nullfor anullinput array.- Parameters:
array – A
Floatarray, may benull.- Returns:
A
floatarray,nullif null array input.- Throws:
java.lang.NullPointerException – Thrown if an array element is
null.
- public static float[] toPrimitive(Float[] array, float valueForNull)[source]¶
Converts an array of object Floats to primitives handling
null.This method returns
nullfor anullinput array.- Parameters:
array – A
Floatarray, may benull.valueForNull – The value to insert if
nullfound.
- Returns:
A
floatarray,nullif null array input.
- public static int[] toPrimitive(Integer[] array)[source]¶
Converts an array of object Integers to primitives.
This method returns
nullfor anullinput array.- Parameters:
array – A
Integerarray, may benull.- Returns:
An
intarray,nullif null array input.- Throws:
java.lang.NullPointerException – Thrown if an array element is
null.
- public static int[] toPrimitive(Integer[] array, int valueForNull)[source]¶
Converts an array of object Integer to primitives handling
null.This method returns
nullfor anullinput array.- Parameters:
array – A
Integerarray, may benull.valueForNull – The value to insert if
nullfound.
- Returns:
An
intarray,nullif null array input.
- public static long[] toPrimitive(Long[] array)[source]¶
Converts an array of object Longs to primitives.
This method returns
nullfor anullinput array.- Parameters:
array – A
Longarray, may benull.- Returns:
A
longarray,nullif null array input.- Throws:
java.lang.NullPointerException – Thrown if an array element is
null.
- public static long[] toPrimitive(Long[] array, long valueForNull)[source]¶
Converts an array of object Long to primitives handling
null.This method returns
nullfor anullinput array.- Parameters:
array – A
Longarray, may benull.valueForNull – The value to insert if
nullfound.
- Returns:
A
longarray,nullif null array input.
- public static Object toPrimitive(Object array)[source]¶
Create an array of primitive type from an array of wrapper types.
This method returns
nullfor anullinput array.- Parameters:
array – An array of wrapper object.
- Returns:
An array of the corresponding primitive type, or the original array.
- Since:
3.5
- public static short[] toPrimitive(Short[] array)[source]¶
Converts an array of object Shorts to primitives.
This method returns
nullfor anullinput array.- Parameters:
array – A
Shortarray, may benull.- Returns:
A
bytearray,nullif null array input.- Throws:
java.lang.NullPointerException – Thrown if an array element is
null.
- public static short[] toPrimitive(Short[] array, short valueForNull)[source]¶
Converts an array of object Short to primitives handling
null.This method returns
nullfor anullinput array.- Parameters:
array – A
Shortarray, may benull.valueForNull – The value to insert if
nullfound.
- Returns:
A
bytearray,nullif null array input.
- public static String toString(Object array)[source]¶
Outputs an array as a String, treating
nullas an empty array.Multi-dimensional arrays are handled correctly, including multi-dimensional primitive arrays.
The format is that of Java source code, for example
{a,b}.- Parameters:
array – The array to get a toString for, may be
null.- Returns:
A String representation of the array, ‘{}’ if null array input.
- public static String toString(Object array, String stringIfNull)[source]¶
Outputs an array as a String handling
nulls.Multi-dimensional arrays are handled correctly, including multi-dimensional primitive arrays.
The format is that of Java source code, for example
{a,b}.- Parameters:
array – The array to get a toString for, may be
null.stringIfNull – The String to return if the array is
null.
- Returns:
A String representation of the array.
- public static String[] toStringArray(Object[] array)[source]¶
Returns an array containing the string representation of each element in the argument array.
This method returns
nullfor anullinput array.- Parameters:
array – The
Object[]to be processed, may benull.- Returns:
String[]of the same size as the source with its element’s string representation,nullif null array input.- Since:
3.6
- public static String[] toStringArray(Object[] array, String valueForNullElements)[source]¶
Returns an array containing the string representation of each element in the argument array handling
nullelements.This method returns
nullfor anullinput array.- Parameters:
array – The Object[] to be processed, may be
null.valueForNullElements – The value to insert if
nullis found.
- Returns:
A
Stringarray,nullif null array input.- Since:
3.6