ArrayUtils

public class org.apache.commons.lang3.ArrayUtils[source]

Operations on arrays, primitive arrays (like int[]) and primitive wrapper arrays (like Integer[]).

This class tries to handle null input gracefully. An exception will not be thrown for a null array input. However, an Object array that contains a null element may throw an exception. Each method documents its behavior.

#ThreadSafe#

Since:

2.0

Constructors

ArrayUtils()

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

EMPTY_BOOLEAN_ARRAY

An empty immutable boolean array.

EMPTY_BOOLEAN_OBJECT_ARRAY

An empty immutable Boolean array.

EMPTY_BYTE_ARRAY

An empty immutable byte array.

EMPTY_BYTE_OBJECT_ARRAY

An empty immutable Byte array.

EMPTY_CHARACTER_OBJECT_ARRAY

An empty immutable Character array.

EMPTY_CHAR_ARRAY

An empty immutable char array.

EMPTY_CLASS_ARRAY

An empty immutable Class array.

EMPTY_DOUBLE_ARRAY

An empty immutable double array.

EMPTY_DOUBLE_OBJECT_ARRAY

An empty immutable Double array.

EMPTY_FIELD_ARRAY

An empty immutable Field array.

EMPTY_FLOAT_ARRAY

An empty immutable float array.

EMPTY_FLOAT_OBJECT_ARRAY

An empty immutable Float array.

EMPTY_INTEGER_OBJECT_ARRAY

An empty immutable Integer array.

EMPTY_INT_ARRAY

An empty immutable int array.

EMPTY_LONG_ARRAY

An empty immutable long array.

EMPTY_LONG_OBJECT_ARRAY

An empty immutable Long array.

EMPTY_METHOD_ARRAY

An empty immutable Method array.

EMPTY_OBJECT_ARRAY

An empty immutable Object array.

EMPTY_SHORT_ARRAY

An empty immutable short array.

EMPTY_SHORT_OBJECT_ARRAY

An empty immutable Short array.

EMPTY_STRING_ARRAY

An empty immutable String array.

EMPTY_THROWABLE_ARRAY

An empty immutable Throwable array.

EMPTY_TYPE_ARRAY

An empty immutable Type array.

INDEX_NOT_FOUND

The index value when an element is not found in a list or array: -1.

SAFE_MAX_ARRAY_LENGTH

The MAX_ARRAY_LENGTH constant from Java’s internal ArraySupport class.

SOFT_MAX_ARRAY_LENGTH

Deprecated. The SOFT_MAX_ARRAY_LENGTH constant from Java’s internal ArraySupport class.

public static final boolean[] EMPTY_BOOLEAN_ARRAY[source]

An empty immutable boolean array.

public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY[source]

An empty immutable Boolean array.

public static final byte[] EMPTY_BYTE_ARRAY[source]

An empty immutable byte array.

public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY[source]

An empty immutable Byte array.

public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY[source]

An empty immutable Character array.

public static final char[] EMPTY_CHAR_ARRAY[source]

An empty immutable char array.

public static final Class<?>[] EMPTY_CLASS_ARRAY[source]

An empty immutable Class array.

public static final double[] EMPTY_DOUBLE_ARRAY[source]

An empty immutable double array.

public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY[source]

An empty immutable Double array.

public static final Field[] EMPTY_FIELD_ARRAY[source]

An empty immutable Field array.

Since:

3.10

public static final float[] EMPTY_FLOAT_ARRAY[source]

An empty immutable float array.

public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY[source]

An empty immutable Float array.

public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY[source]

An empty immutable Integer array.

public static final int[] EMPTY_INT_ARRAY[source]

An empty immutable int array.

public static final long[] EMPTY_LONG_ARRAY[source]

An empty immutable long array.

public static final Long[] EMPTY_LONG_OBJECT_ARRAY[source]

An empty immutable Long array.

public static final Method[] EMPTY_METHOD_ARRAY[source]

An empty immutable Method array.

Since:

3.10

public static final Object[] EMPTY_OBJECT_ARRAY[source]

An empty immutable Object array.

public static final short[] EMPTY_SHORT_ARRAY[source]

An empty immutable short array.

public static final Short[] EMPTY_SHORT_OBJECT_ARRAY[source]

An empty immutable Short array.

public static final String[] EMPTY_STRING_ARRAY[source]

An empty immutable String array.

public static final Throwable[] EMPTY_THROWABLE_ARRAY[source]

An empty immutable Throwable array.

Since:

3.10

public static final Type[] EMPTY_TYPE_ARRAY[source]

An empty immutable Type array.

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 from java.util.List.

public static final int SAFE_MAX_ARRAY_LENGTH = 2147483639[source]

The MAX_ARRAY_LENGTH constant 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_LENGTH constant from Java’s internal ArraySupport class.

Since:

3.19.0

Methods

add(boolean[], boolean)

Copies the given array and adds the given element at the end of the new array.

add(boolean[], int, boolean)

Deprecated. Inserts the specified element at the specified position in the array.

add(byte[], byte)

Copies the given array and adds the given element at the end of the new array.

add(byte[], int, byte)

Deprecated. Inserts the specified element at the specified position in the array.

add(char[], char)

Copies the given array and adds the given element at the end of the new array.

add(char[], int, char)

Deprecated. Inserts the specified element at the specified position in the array.

add(double[], double)

Copies the given array and adds the given element at the end of the new array.

add(double[], int, double)

Deprecated. Inserts the specified element at the specified position in the array.

add(float[], float)

Copies the given array and adds the given element at the end of the new array.

add(float[], int, float)

Deprecated. Inserts the specified element at the specified position in the array.

add(int[], int)

Copies the given array and adds the given element at the end of the new array.

add(int[], int, int)

Deprecated. Inserts the specified element at the specified position in the array.

add(Object[], int, Object)

Deprecated. Inserts the specified element at the specified position in the array.

add(Object[], Object)

Copies the given array and adds the given element at the end of the new array.

add(long[], int, long)

Deprecated. Inserts the specified element at the specified position in the array.

add(long[], long)

Copies the given array and adds the given element at the end of the new array.

add(short[], int, short)

Deprecated. Inserts the specified element at the specified position in the array.

add(short[], short)

Copies the given array and adds the given element at the end of the new array.

addAll(boolean[], boolean[])

Adds all the elements of the given arrays into a new array.

addAll(byte[], byte[])

Adds all the elements of the given arrays into a new array.

addAll(char[], char[])

Adds all the elements of the given arrays into a new array.

addAll(double[], double[])

Adds all the elements of the given arrays into a new array.

addAll(float[], float[])

Adds all the elements of the given arrays into a new array.

addAll(int[], int[])

Adds all the elements of the given arrays into a new array.

addAll(Object[], Object[])

Adds all the elements of the given arrays into a new array.

addAll(long[], long[])

Adds all the elements of the given arrays into a new array.

addAll(short[], short[])

Adds all the elements of the given arrays into a new array.

addFirst(boolean[], boolean)

Copies the given array and adds the given element at the beginning of the new array.

addFirst(byte[], byte)

Copies the given array and adds the given element at the beginning of the new array.

addFirst(char[], char)

Copies the given array and adds the given element at the beginning of the new array.

addFirst(double[], double)

Copies the given array and adds the given element at the beginning of the new array.

addFirst(float[], float)

Copies the given array and adds the given element at the beginning of the new array.

addFirst(int[], int)

Copies the given array and adds the given element at the beginning of the new array.

addFirst(Object[], Object)

Copies the given array and adds the given element at the beginning of the new array.

addFirst(long[], long)

Copies the given array and adds the given element at the beginning of the new array.

addFirst(short[], short)

Copies the given array and adds the given element at the beginning of the new array.

arraycopy(Object, int, int, int, Function)

A fluent version of System#arraycopy(Object, int, Object, int, int) that returns the destination array.

arraycopy(Object, int, int, int, Supplier)

A fluent version of System#arraycopy(Object, int, Object, int, int) that returns the destination array.

arraycopy(Object, int, Object, int, int)

A fluent version of System#arraycopy(Object, int, Object, int, int) that returns the destination array.

clone(boolean[])

Clones an array or returns null.

clone(byte[])

Clones an array or returns null.

clone(char[])

Clones an array or returns null.

clone(double[])

Clones an array or returns null.

clone(float[])

Clones an array or returns null.

clone(int[])

Clones an array or returns null.

clone(Object[])

Shallow clones an array or returns null.

clone(long[])

Clones an array or returns null.

clone(short[])

Clones an array or returns null.

concat(boolean[][])

Concatenates multiple boolean arrays into a single array.

concat(byte[][])

Concatenates multiple byte arrays into a single array.

concat(char[][])

Concatenates multiple char arrays into a single array.

concat(double[][])

Concatenates multiple double arrays into a single array.

concat(float[][])

Concatenates multiple float arrays into a single array.

concat(int[][])

Concatenates multiple int arrays into a single array.

concat(long[][])

Concatenates multiple long arrays into a single array.

concat(short[][])

Concatenates multiple short arrays into a single array.

contains(boolean[], boolean)

Checks if the value is in the given array.

contains(byte[], byte)

Checks if the value is in the given array.

contains(char[], char)

Checks if the value is in the given array.

contains(double[], double)

Checks if the value is in the given array.

contains(double[], double, double)

Checks if a value falling within the given tolerance is in the given array.

contains(float[], float)

Checks if the value is in the given array.

contains(int[], int)

Checks if the value is in the given array.

contains(Object[], Object)

Checks if the object is in the given array.

contains(long[], long)

Checks if the value is in the given array.

contains(short[], short)

Checks if the value is in the given array.

containsAny(int[], int[])

Checks if any of the ints are in the given array.

containsAny(Object[], Object[])

Checks if any of the objects are in the given array.

get(Object[], int)

Gets the nTh element of an array or null if the index is out of bounds or the array is null.

get(Object[], int, Object)

Gets the nTh element of an array or a default value if the index is out of bounds.

getComponentType(Object[])

Gets an array’s component type.

getDimensions(Object)

Gets the number of dimensions of an array.

getLength(Object)

Gets the length of the specified array.

hashCode(Object)

Gets a hash code for an array handling multidimensional arrays.

indexOf(boolean[], boolean)

Finds the index of the given value in the array.

indexOf(boolean[], boolean, int)

Finds the index of the given value in the array starting at the given index.

indexOf(byte[], byte)

Finds the index of the given value in the array.

indexOf(byte[], byte, int)

Finds the index of the given value in the array starting at the given index.

indexOf(char[], char)

Finds the index of the given value in the array.

indexOf(char[], char, int)

Finds the index of the given value in the array starting at the given index.

indexOf(double[], double)

Finds the index of the given value in the array.

indexOf(double[], double, double)

Finds the index of the given value within a given tolerance in the array.

indexOf(double[], double, int)

Finds the index of the given value in the array starting at the given index.

indexOf(double[], double, int, double)

Finds the index of the given value in the array starting at the given index.

indexOf(float[], float)

Finds the index of the given value in the array.

indexOf(float[], float, int)

Finds the index of the given value in the array starting at the given index.

indexOf(int[], int)

Finds the index of the given value in the array.

indexOf(int[], int, int)

Finds the index of the given value in the array starting at the given index.

indexOf(Object[], Object)

Finds the index of the given object in the array.

indexOf(Object[], Object, int)

Finds the index of the given object in the array starting at the given index.

indexOf(long[], long)

Finds the index of the given value in the array.

indexOf(long[], long, int)

Finds the index of the given value in the array starting at the given index.

indexOf(short[], short)

Finds the index of the given value in the array.

indexOf(short[], short, int)

Finds the index of the given value in the array starting at the given index.

indexesOf(boolean[], boolean)

Finds the indices of the given value in the array.

indexesOf(boolean[], boolean, int)

Finds the indices of the given value in the array starting at the given index.

indexesOf(byte[], byte)

Finds the indices of the given value in the array.

indexesOf(byte[], byte, int)

Finds the indices of the given value in the array starting at the given index.

indexesOf(char[], char)

Finds the indices of the given value in the array.

indexesOf(char[], char, int)

Finds the indices of the given value in the array starting at the given index.

indexesOf(double[], double)

Finds the indices of the given value in the array.

indexesOf(double[], double, double)

Finds the indices of the given value within a given tolerance in the array.

indexesOf(double[], double, int)

Finds the indices of the given value in the array starting at the given index.

indexesOf(double[], double, int, double)

Finds the indices of the given value in the array starting at the given index.

indexesOf(float[], float)

Finds the indices of the given value in the array.

indexesOf(float[], float, int)

Finds the indices of the given value in the array starting at the given index.

indexesOf(int[], int)

Finds the indices of the given value in the array.

indexesOf(int[], int, int)

Finds the indices of the given value in the array starting at the given index.

indexesOf(Object[], Object)

Finds the indices of the given object in the array.

indexesOf(Object[], Object, int)

Finds the indices of the given object in the array starting at the given index.

indexesOf(long[], long)

Finds the indices of the given value in the array.

indexesOf(long[], long, int)

Finds the indices of the given value in the array starting at the given index.

indexesOf(short[], short)

Finds the indices of the given value in the array.

indexesOf(short[], short, int)

Finds the indices of the given value in the array starting at the given index.

insert(int, boolean[], boolean[])

Inserts elements into an array at the given index (starting from zero).

insert(int, byte[], byte[])

Inserts elements into an array at the given index (starting from zero).

insert(int, char[], char[])

Inserts elements into an array at the given index (starting from zero).

insert(int, double[], double[])

Inserts elements into an array at the given index (starting from zero).

insert(int, float[], float[])

Inserts elements into an array at the given index (starting from zero).

insert(int, int[], int[])

Inserts elements into an array at the given index (starting from zero).

insert(int, Object[], Object[])

Inserts elements into an array at the given index (starting from zero).

insert(int, long[], long[])

Inserts elements into an array at the given index (starting from zero).

insert(int, short[], short[])

Inserts elements into an array at the given index (starting from zero).

isArrayIndexValid(Object[], int)

Tests whether a given array can safely be accessed at the given index.

isEmpty(boolean[])

Tests whether an array of primitive booleans is empty or null.

isEmpty(byte[])

Tests whether an array of primitive bytes is empty or null.

isEmpty(char[])

Tests whether an array of primitive chars is empty or null.

isEmpty(double[])

Tests whether an array of primitive doubles is empty or null.

isEmpty(float[])

Tests whether an array of primitive floats is empty or null.

isEmpty(int[])

Tests whether an array of primitive ints is empty or null.

isEmpty(Object[])

Tests whether an array of Objects is empty or null.

isEmpty(long[])

Tests whether an array of primitive longs is empty or null.

isEmpty(short[])

Tests whether an array of primitive shorts is empty or null.

isEquals(Object, Object)

Deprecated. Tests whether two arrays have equal content, using equals(), handling multidimensional arrays correctly.

isNotEmpty(boolean[])

Tests whether an array of primitive booleans is not empty and not null.

isNotEmpty(byte[])

Tests whether an array of primitive bytes is not empty and not null.

isNotEmpty(char[])

Tests whether an array of primitive chars is not empty and not null.

isNotEmpty(double[])

Tests whether an array of primitive doubles is not empty and not null.

isNotEmpty(float[])

Tests whether an array of primitive floats is not empty and not null.

isNotEmpty(int[])

Tests whether an array of primitive ints is not empty and not null.

isNotEmpty(Object[])

Tests whether an array of Objects is not empty and not null.

isNotEmpty(long[])

Tests whether an array of primitive longs is not empty and not null.

isNotEmpty(short[])

Tests whether an array of primitive shorts is not empty and not null.

isSameLength(boolean[], boolean[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(byte[], byte[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(char[], char[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(double[], double[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(float[], float[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(int[], int[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(Object, Object)

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(Object[], Object[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(long[], long[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameLength(short[], short[])

Tests whether two arrays are the same length, treating null arrays as length 0.

isSameType(Object, Object)

Tests whether two arrays are the same type taking into account multidimensional arrays.

isSorted(boolean[])

Tests whether the provided array is sorted according to natural ordering (false before true).

isSorted(byte[])

Tests whether the provided array is sorted according to natural ordering.

isSorted(char[])

Tests whether the provided array is sorted according to natural ordering.

isSorted(double[])

Tests whether the provided array is sorted according to natural ordering.

isSorted(float[])

Tests whether the provided array is sorted according to natural ordering.

isSorted(int[])

Tests whether the provided array is sorted according to natural ordering.

isSorted(Comparable[])

Tests whether the provided array is sorted according to the class’s compareTo method.

isSorted(Object[], Comparator)

Tests whether the provided array is sorted according to the provided Comparator.

isSorted(long[])

Tests whether the provided array is sorted according to natural ordering.

isSorted(short[])

Tests whether the provided array is sorted according to natural ordering.

lastIndexOf(boolean[], boolean)

Finds the last index of the given value within the array.

lastIndexOf(boolean[], boolean, int)

Finds the last index of the given value in the array starting at the given index.

lastIndexOf(byte[], byte)

Finds the last index of the given value within the array.

lastIndexOf(byte[], byte, int)

Finds the last index of the given value in the array starting at the given index.

lastIndexOf(char[], char)

Finds the last index of the given value within the array.

lastIndexOf(char[], char, int)

Finds the last index of the given value in the array starting at the given index.

lastIndexOf(double[], double)

Finds the last index of the given value within the array.

lastIndexOf(double[], double, double)

Finds the last index of the given value within a given tolerance in the array.

lastIndexOf(double[], double, int)

Finds the last index of the given value in the array starting at the given index.

lastIndexOf(double[], double, int, double)

Finds the last index of the given value in the array starting at the given index.

lastIndexOf(float[], float)

Finds the last index of the given value within the array.

lastIndexOf(float[], float, int)

Finds the last index of the given value in the array starting at the given index.

lastIndexOf(int[], int)

Finds the last index of the given value within the array.

lastIndexOf(int[], int, int)

Finds the last index of the given value in the array starting at the given index.

lastIndexOf(Object[], Object)

Finds the last index of the given object within the array.

lastIndexOf(Object[], Object, int)

Finds the last index of the given object in the array starting at the given index.

lastIndexOf(long[], long)

Finds the last index of the given value within the array.

lastIndexOf(long[], long, int)

Finds the last index of the given value in the array starting at the given index.

lastIndexOf(short[], short)

Finds the last index of the given value within the array.

lastIndexOf(short[], short, int)

Finds the last index of the given value in the array starting at the given index.

newInstance(Class, int)

Delegates to Array#newInstance(Class,int) using generics.

nullTo(Object[], Object[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(boolean[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(byte[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(char[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(double[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(float[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(int[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Boolean[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Byte[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Character[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Class[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Double[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Float[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Integer[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Long[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Object[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Object[], Class)

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(Short[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(String[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(long[])

Defensive programming technique to change a null reference to an empty one.

nullToEmpty(short[])

Defensive programming technique to change a null reference to an empty one.

remove(boolean[], int)

Removes the element at the specified position from the specified array.

remove(byte[], int)

Removes the element at the specified position from the specified array.

remove(char[], int)

Removes the element at the specified position from the specified array.

remove(double[], int)

Removes the element at the specified position from the specified array.

remove(float[], int)

Removes the element at the specified position from the specified array.

remove(int[], int)

Removes the element at the specified position from the specified array.

remove(Object[], int)

Removes the element at the specified position from the specified array.

remove(long[], int)

Removes the element at the specified position from the specified array.

remove(short[], int)

Removes the element at the specified position from the specified array.

removeAll(boolean[], int[])

Removes the elements at the specified positions from the specified array.

removeAll(byte[], int[])

Removes the elements at the specified positions from the specified array.

removeAll(char[], int[])

Removes the elements at the specified positions from the specified array.

removeAll(double[], int[])

Removes the elements at the specified positions from the specified array.

removeAll(float[], int[])

Removes the elements at the specified positions from the specified array.

removeAll(int[], int[])

Removes the elements at the specified positions from the specified array.

removeAll(Object[], int[])

Removes the elements at the specified positions from the specified array.

removeAll(long[], int[])

Removes the elements at the specified positions from the specified array.

removeAll(short[], int[])

Removes the elements at the specified positions from the specified array.

removeAllOccurences(boolean[], boolean)

Deprecated. Removes the occurrences of the specified element from the specified boolean array.

removeAllOccurences(byte[], byte)

Deprecated. Removes the occurrences of the specified element from the specified byte array.

removeAllOccurences(char[], char)

Deprecated. Removes the occurrences of the specified element from the specified char array.

removeAllOccurences(double[], double)

Deprecated. Removes the occurrences of the specified element from the specified double array.

removeAllOccurences(float[], float)

Deprecated. Removes the occurrences of the specified element from the specified float array.

removeAllOccurences(int[], int)

Deprecated. Removes the occurrences of the specified element from the specified int array.

removeAllOccurences(Object[], Object)

Deprecated. Removes the occurrences of the specified element from the specified array.

removeAllOccurences(long[], long)

Deprecated. Removes the occurrences of the specified element from the specified long array.

removeAllOccurences(short[], short)

Deprecated. Removes the occurrences of the specified element from the specified short array.

removeAllOccurrences(boolean[], boolean)

Removes the occurrences of the specified element from the specified boolean array.

removeAllOccurrences(byte[], byte)

Removes the occurrences of the specified element from the specified byte array.

removeAllOccurrences(char[], char)

Removes the occurrences of the specified element from the specified char array.

removeAllOccurrences(double[], double)

Removes the occurrences of the specified element from the specified double array.

removeAllOccurrences(float[], float)

Removes the occurrences of the specified element from the specified float array.

removeAllOccurrences(int[], int)

Removes the occurrences of the specified element from the specified int array.

removeAllOccurrences(Object[], Object)

Removes the occurrences of the specified element from the specified array.

removeAllOccurrences(long[], long)

Removes the occurrences of the specified element from the specified long array.

removeAllOccurrences(short[], short)

Removes the occurrences of the specified element from the specified short array.

removeElement(boolean[], boolean)

Removes the first occurrence of the specified element from the specified array.

removeElement(byte[], byte)

Removes the first occurrence of the specified element from the specified array.

removeElement(char[], char)

Removes the first occurrence of the specified element from the specified array.

removeElement(double[], double)

Removes the first occurrence of the specified element from the specified array.

removeElement(float[], float)

Removes the first occurrence of the specified element from the specified array.

removeElement(int[], int)

Removes the first occurrence of the specified element from the specified array.

removeElement(Object[], Object)

Removes the first occurrence of the specified element from the specified array.

removeElement(long[], long)

Removes the first occurrence of the specified element from the specified array.

removeElement(short[], short)

Removes the first occurrence of the specified element from the specified array.

removeElements(boolean[], boolean[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

removeElements(byte[], byte[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

removeElements(char[], char[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

removeElements(double[], double[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

removeElements(float[], float[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

removeElements(int[], int[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

removeElements(Object[], Object[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

removeElements(long[], long[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

removeElements(short[], short[])

Removes occurrences of specified elements, in specified quantities, from the specified array.

reverse(boolean[])

Reverses the order of the given array.

reverse(boolean[], int, int)

Reverses the order of the given array in the given range.

reverse(byte[])

Reverses the order of the given array.

reverse(byte[], int, int)

Reverses the order of the given array in the given range.

reverse(char[])

Reverses the order of the given array.

reverse(char[], int, int)

Reverses the order of the given array in the given range.

reverse(double[])

Reverses the order of the given array.

reverse(double[], int, int)

Reverses the order of the given array in the given range.

reverse(float[])

Reverses the order of the given array.

reverse(float[], int, int)

Reverses the order of the given array in the given range.

reverse(int[])

Reverses the order of the given array.

reverse(int[], int, int)

Reverses the order of the given array in the given range.

reverse(Object[])

Reverses the order of the given array.

reverse(Object[], int, int)

Reverses the order of the given array in the given range.

reverse(long[])

Reverses the order of the given array.

reverse(long[], int, int)

Reverses the order of the given array in the given range.

reverse(short[])

Reverses the order of the given array.

reverse(short[], int, int)

Reverses the order of the given array in the given range.

setAll(Object[], IntFunction)

Sets all elements of the specified array, using the provided generator supplier to compute each element.

setAll(Object[], Supplier)

Sets all elements of the specified array, using the provided generator supplier to compute each element.

shift(boolean[], int)

Shifts the order of the given boolean array.

shift(boolean[], int, int, int)

Shifts the order of a series of elements in the given boolean array.

shift(byte[], int)

Shifts the order of the given byte array.

shift(byte[], int, int, int)

Shifts the order of a series of elements in the given byte array.

shift(char[], int)

Shifts the order of the given char array.

shift(char[], int, int, int)

Shifts the order of a series of elements in the given char array.

shift(double[], int)

Shifts the order of the given double array.

shift(double[], int, int, int)

Shifts the order of a series of elements in the given double array.

shift(float[], int)

Shifts the order of the given float array.

shift(float[], int, int, int)

Shifts the order of a series of elements in the given float array.

shift(int[], int)

Shifts the order of the given int array.

shift(int[], int, int, int)

Shifts the order of a series of elements in the given int array.

shift(Object[], int)

Shifts the order of the given array.

shift(Object[], int, int, int)

Shifts the order of a series of elements in the given array.

shift(long[], int)

Shifts the order of the given long array.

shift(long[], int, int, int)

Shifts the order of a series of elements in the given long array.

shift(short[], int)

Shifts the order of the given short array.

shift(short[], int, int, int)

Shifts the order of a series of elements in the given short array.

shuffle(boolean[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(boolean[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(byte[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(byte[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(char[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(char[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(double[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(double[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(float[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(float[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(int[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(int[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(Object[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(Object[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(long[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(long[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(short[])

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

shuffle(short[], Random)

Shuffles randomly the elements of the specified array using the Fisher-Yates shuffle algorithm.

startsWith(byte[], byte[])

Tests whether the given data array starts with an expected array, for example, signature bytes.

subarray(boolean[], int, int)

Produces a new boolean array containing the elements between the start and end indices.

subarray(byte[], int, int)

Produces a new byte array containing the elements between the start and end indices.

subarray(char[], int, int)

Produces a new char array containing the elements between the start and end indices.

subarray(double[], int, int)

Produces a new double array containing the elements between the start and end indices.

subarray(float[], int, int)

Produces a new float array containing the elements between the start and end indices.

subarray(int[], int, int)

Produces a new int array containing the elements between the start and end indices.

subarray(Object[], int, int)

Produces a new array containing the elements between the start and end indices.

subarray(long[], int, int)

Produces a new long array containing the elements between the start and end indices.

subarray(short[], int, int)

Produces a new short array containing the elements between the start and end indices.

swap(boolean[], int, int)

Swaps two elements in the given boolean array.

swap(boolean[], int, int, int)

Swaps a series of elements in the given boolean array.

swap(byte[], int, int)

Swaps two elements in the given byte array.

swap(byte[], int, int, int)

Swaps a series of elements in the given byte array.

swap(char[], int, int)

Swaps two elements in the given char array.

swap(char[], int, int, int)

Swaps a series of elements in the given char array.

swap(double[], int, int)

Swaps two elements in the given double array.

swap(double[], int, int, int)

Swaps a series of elements in the given double array.

swap(float[], int, int)

Swaps two elements in the given float array.

swap(float[], int, int, int)

Swaps a series of elements in the given float array.

swap(int[], int, int)

Swaps two elements in the given int array.

swap(int[], int, int, int)

Swaps a series of elements in the given int array.

swap(Object[], int, int)

Swaps two elements in the given array.

swap(Object[], int, int, int)

Swaps a series of elements in the given array.

swap(long[], int, int)

Swaps two elements in the given long array.

swap(long[], int, int, int)

Swaps a series of elements in the given long array.

swap(short[], int, int)

Swaps two elements in the given short array.

swap(short[], int, int, int)

Swaps a series of elements in the given short array.

toArray(Object[])

Create a type-safe generic array.

toMap(Object[])

Converts the given array into a java.util.Map.

toObject(boolean[])

Converts an array of primitive booleans to objects.

toObject(byte[])

Converts an array of primitive bytes to objects.

toObject(char[])

Converts an array of primitive chars to objects.

toObject(double[])

Converts an array of primitive doubles to objects.

toObject(float[])

Converts an array of primitive floats to objects.

toObject(int[])

Converts an array of primitive ints to objects.

toObject(long[])

Converts an array of primitive longs to objects.

toObject(short[])

Converts an array of primitive shorts to objects.

toPrimitive(Boolean[])

Converts an array of object Booleans to primitives.

toPrimitive(Boolean[], boolean)

Converts an array of object Booleans to primitives handling null.

toPrimitive(Byte[])

Converts an array of object Bytes to primitives.

toPrimitive(Byte[], byte)

Converts an array of object Bytes to primitives handling null.

toPrimitive(Character[])

Converts an array of object Characters to primitives.

toPrimitive(Character[], char)

Converts an array of object Character to primitives handling null.

toPrimitive(Double[])

Converts an array of object Doubles to primitives.

toPrimitive(Double[], double)

Converts an array of object Doubles to primitives handling null.

toPrimitive(Float[])

Converts an array of object Floats to primitives.

toPrimitive(Float[], float)

Converts an array of object Floats to primitives handling null.

toPrimitive(Integer[])

Converts an array of object Integers to primitives.

toPrimitive(Integer[], int)

Converts an array of object Integer to primitives handling null.

toPrimitive(Long[])

Converts an array of object Longs to primitives.

toPrimitive(Long[], long)

Converts an array of object Long to primitives handling null.

toPrimitive(Object)

Create an array of primitive type from an array of wrapper types.

toPrimitive(Short[])

Converts an array of object Shorts to primitives.

toPrimitive(Short[], short)

Converts an array of object Short to primitives handling null.

toString(Object)

Outputs an array as a String, treating null as an empty array.

toString(Object, String)

Outputs an array as a String handling nulls.

toStringArray(Object[])

Returns an array containing the string representation of each element in the argument array.

toStringArray(Object[], String)

Returns an array containing the string representation of each element in the argument array handling null elements.

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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add(null, 0, true)          = [true]
ArrayUtils.add([true], 0, false)       = [false, true]
ArrayUtils.add([false], 1, true)       = [false, true]
ArrayUtils.add([true, false], 1, true) = [true, true, false]
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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add([1], 0, 2)         = [2, 1]
ArrayUtils.add([2, 6], 2, 3)      = [2, 6, 3]
ArrayUtils.add([2, 6], 0, 1)      = [1, 2, 6]
ArrayUtils.add([2, 6, 3], 2, 1)   = [2, 6, 1, 3]
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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add(null, 0, 'a')            = ['a']
ArrayUtils.add(['a'], 0, 'b')           = ['b', 'a']
ArrayUtils.add(['a', 'b'], 0, 'c')      = ['c', 'a', 'b']
ArrayUtils.add(['a', 'b'], 1, 'k')      = ['a', 'k', 'b']
ArrayUtils.add(['a', 'b', 'c'], 1, 't') = ['a', 't', 'b', 'c']
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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add([1.1], 0, 2.2)              = [2.2, 1.1]
ArrayUtils.add([2.3, 6.4], 2, 10.5)        = [2.3, 6.4, 10.5]
ArrayUtils.add([2.6, 6.7], 0, -4.8)        = [-4.8, 2.6, 6.7]
ArrayUtils.add([2.9, 6.0, 0.3], 2, 1.0)    = [2.9, 6.0, 1.0, 0.3]
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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add([1.1f], 0, 2.2f)               = [2.2f, 1.1f]
ArrayUtils.add([2.3f, 6.4f], 2, 10.5f)        = [2.3f, 6.4f, 10.5f]
ArrayUtils.add([2.6f, 6.7f], 0, -4.8f)        = [-4.8f, 2.6f, 6.7f]
ArrayUtils.add([2.9f, 6.0f, 0.3f], 2, 1.0f)   = [2.9f, 6.0f, 1.0f, 0.3f]
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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add([1], 0, 2)         = [2, 1]
ArrayUtils.add([2, 6], 2, 10)     = [2, 6, 10]
ArrayUtils.add([2, 6], 0, -4)     = [-4, 2, 6]
ArrayUtils.add([2, 6, 3], 2, 1)   = [2, 6, 1, 3]
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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add(null, 0, null)      = 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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add([1L], 0, 2L)           = [2L, 1L]
ArrayUtils.add([2L, 6L], 2, 10L)      = [2L, 6L, 10L]
ArrayUtils.add([2L, 6L], 0, -4L)      = [-4L, 2L, 6L]
ArrayUtils.add([2L, 6L, 3L], 2, 1L)   = [2L, 6L, 1L, 3L]
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 of null input arrays differs in the new method: inserting X into a null array results in null not X.

Inserts the specified element at the specified position in the array. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method returns a new array with the same elements of the input array plus the given element on the specified position. The component type of the returned array is always the same as that of the input array.

If the input array is null, a new one element array is returned whose component type is the same as the element.

ArrayUtils.add([1], 0, 2)         = [2, 1]
ArrayUtils.add([2, 6], 2, 10)     = [2, 6, 10]
ArrayUtils.add([2, 6], 0, -4)     = [-4, 2, 6]
ArrayUtils.add([2, 6, 3], 2, 1)   = [2, 6, 1, 3]
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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(null, null)     = null
ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
ArrayUtils.addAll(null, null)     = null
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, null if both arrays are null. The type of the new array is the type of the first array, unless the first array is null, in which case the type is the same as the second array.

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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
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 array1 followed by all of the elements array2. When an array is returned, it is always a new array.

ArrayUtils.addAll(array1, null)   = cloned copy of array1
ArrayUtils.addAll(null, array2)   = cloned copy of array2
ArrayUtils.addAll([], [])         = []
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 src array could not be stored into the dest array because of a type mismatch.

  • java.lang.NullPointerException – Thrown if either src or dest is null.

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 src array could not be stored into the dest array because of a type mismatch.

  • java.lang.NullPointerException – Thrown if either src or dest is null.

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 src array could not be stored into the dest array because of a type mismatch.

  • java.lang.NullPointerException – Thrown if either src or dest is null.

Since:

3.15.0

public static boolean[] clone(boolean[] array)[source]

Clones an array or returns null.

This method returns null for a null input array.

Parameters:

array – The array to clone, may be null.

Returns:

The cloned array, null if null input.

public static byte[] clone(byte[] array)[source]

Clones an array or returns null.

This method returns null for a null input array.

Parameters:

array – The array to clone, may be null.

Returns:

The cloned array, null if null input.

public static char[] clone(char[] array)[source]

Clones an array or returns null.

This method returns null for a null input array.

Parameters:

array – The array to clone, may be null.

Returns:

The cloned array, null if null input.

public static double[] clone(double[] array)[source]

Clones an array or returns null.

This method returns null for a null input array.

Parameters:

array – The array to clone, may be null.

Returns:

The cloned array, null if null input.

public static float[] clone(float[] array)[source]

Clones an array or returns null.

This method returns null for a null input array.

Parameters:

array – The array to clone, may be null.

Returns:

The cloned array, null if null input.

public static int[] clone(int[] array)[source]

Clones an array or returns null.

This method returns null for a null input array.

Parameters:

array – The array to clone, may be null.

Returns:

The cloned array, null if null input.

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 null for a null input array.

Type parameters:

<T> – the component type of the array.

Parameters:

array – The array to shallow clone, may be null.

Returns:

The cloned array, null if null input.

public static long[] clone(long[] array)[source]

Clones an array or returns null.

This method returns null for a null input array.

Parameters:

array – The array to clone, may be null.

Returns:

The cloned array, null if null input.

public static short[] clone(short[] array)[source]

Clones an array or returns null.

This method returns null for a null input array.

Parameters:

array – The array to clone, may be null.

Returns:

The cloned array, null if null input.

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 false if a null array is passed in.

Parameters:
  • array – The array to search.

  • valueToFind – The value to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(byte[]) and Arrays#binarySearch(byte[], byte).

Parameters:
  • array – The array to search.

  • valueToFind – The value to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(char[]) and Arrays#binarySearch(char[], char).

Parameters:
  • array – The array to search.

  • valueToFind – The value to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(double[]) and Arrays#binarySearch(double[], double).

Parameters:
  • array – The array to search.

  • valueToFind – The value to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(double[]) and Arrays#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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(float[]) and Arrays#binarySearch(float[], float).

Parameters:
  • array – The array to search.

  • valueToFind – The value to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(int[]) and Arrays#binarySearch(int[], int).

Parameters:
  • array – The array to search.

  • valueToFind – The value to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(Object[], Comparator) and Arrays#binarySearch(Object[], Object).

Parameters:
  • array – The array to search, may be null.

  • objectToFind – The object to find, may be null.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(long[]) and Arrays#binarySearch(long[], long).

Parameters:
  • array – The array to search.

  • valueToFind – The value to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(short[]) and Arrays#binarySearch(short[], short).

Parameters:
  • array – The array to search.

  • valueToFind – The value to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(int[]) and Arrays#binarySearch(int[], int).

Parameters:
  • array – The array to search.

  • objectsToFind – any of the ints to find.

Returns:

true if 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 false if a null array is passed in.

If the array elements you are searching implement Comparator, consider whether it is worth using Arrays#sort(Object[], Comparator) and Arrays#binarySearch(Object[], Object).

Parameters:
  • array – The array to search, may be null.

  • objectsToFind – any of the objects to find, may be null.

Returns:

true if 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:

JVM specification Field Descriptors

public static int getLength(Object array)[source]

Gets the length of the specified array. This method handles Object arrays and primitive arrays.

If the input array is null, 0 is returned.

ArrayUtils.getLength(null)            = 0
ArrayUtils.getLength([])              = 0
ArrayUtils.getLength([null])          = 1
ArrayUtils.getLength([true, false])   = 2
ArrayUtils.getLength([1, 2, 3])       = 3
ArrayUtils.getLength(["a", "b", "c"]) = 3
Parameters:

array – The array to retrieve the length from, may be null.

Returns:

The length of the array, or 0 if the array is null.

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:

HashCodeBuilder

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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 null input 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 null array 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 array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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 array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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 array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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 array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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 array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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 array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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 array and values.

Parameters:
  • index – The position within array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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 array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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 array to 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 null if the given array is null.

Throws:
  • java.lang.IndexOutOfBoundsException – Thrown if array is provided and either index < 0 or index > 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:

true if the array is empty or null.

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:

true if the array is empty or null.

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:

true if the array is empty or null.

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:

true if the array is empty or null.

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:

true if the array is empty or null.

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:

true if the array is empty or null.

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:

true if the array is empty or null.

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:

true if the array is empty or null.

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:

true if the array is empty or null.

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:

true if 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:

true if the array is not empty and not null.

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:

true if the array is not empty and not null.

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:

true if the array is not empty and not null.

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:

true if the array is not empty and not null.

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:

true if the array is not empty and not null.

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:

true if the array is not empty and not null.

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:

true if the array is not empty and not null.

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:

true if the array is not empty and not null.

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:

true if the array is not empty and not null.

Since:

2.5

public static boolean isSameLength(boolean[] array1, boolean[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

Parameters:
  • array1 – The first array, may be null.

  • array2 – The second array, may be null.

Returns:

true if length of arrays matches, treating null as an empty array.

public static boolean isSameLength(byte[] array1, byte[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

Parameters:
  • array1 – The first array, may be null.

  • array2 – The second array, may be null.

Returns:

true if length of arrays matches, treating null as an empty array.

public static boolean isSameLength(char[] array1, char[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

Parameters:
  • array1 – The first array, may be null.

  • array2 – The second array, may be null.

Returns:

true if length of arrays matches, treating null as an empty array.

public static boolean isSameLength(double[] array1, double[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

Parameters:
  • array1 – The first array, may be null.

  • array2 – The second array, may be null.

Returns:

true if length of arrays matches, treating null as an empty array.

public static boolean isSameLength(float[] array1, float[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

Parameters:
  • array1 – The first array, may be null.

  • array2 – The second array, may be null.

Returns:

true if length of arrays matches, treating null as an empty array.

public static boolean isSameLength(int[] array1, int[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

Parameters:
  • array1 – The first array, may be null.

  • array2 – The second array, may be null.

Returns:

true if length of arrays matches, treating null as an empty array.

public static boolean isSameLength(Object array1, Object array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

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:

true if length of arrays matches, treating null as an empty array.

Since:

3.11

public static boolean isSameLength(Object[] array1, Object[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

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:

true if length of arrays matches, treating null as an empty array.

public static boolean isSameLength(long[] array1, long[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

Parameters:
  • array1 – The first array, may be null.

  • array2 – The second array, may be null.

Returns:

true if length of arrays matches, treating null as an empty array.

public static boolean isSameLength(short[] array1, short[] array2)[source]

Tests whether two arrays are the same length, treating null arrays as length 0.

Parameters:
  • array1 – The first array, may be null.

  • array2 – The second array, may be null.

Returns:

true if length of arrays matches, treating null as 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:

true if 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 (false before true).

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 compareTo method.

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 Comparator to compare over.

Type parameters:

<T> – The datatype of the array.

Returns:

whether the array is sorted.

Throws:

java.lang.NullPointerException – Thrown if comparator is null.

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) if null array 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input 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 or null array 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 a null input 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 a null input 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 or null array 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 a null input array.

A negative startIndex will return #INDEX_NOT_FOUND (-1). A startIndex larger than the array length will search from the end of the array.

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 or null array 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 componentType parameter is null.

Since:

3.13.0

public static <T> T[] nullTo(T[] array, T[] defaultArray)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns a default array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Type parameters:

<T> – The array type.

Parameters:
  • array – The array to check for null or empty

  • defaultArray – A default array, usually empty.

Returns:

The same array, or defaultArray if null or empty input.

Since:

3.15.0

public static boolean[] nullToEmpty(boolean[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static byte[] nullToEmpty(byte[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static char[] nullToEmpty(char[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static double[] nullToEmpty(double[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static float[] nullToEmpty(float[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static int[] nullToEmpty(int[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static Boolean[] nullToEmpty(Boolean[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static Byte[] nullToEmpty(Byte[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static Character[] nullToEmpty(Character[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static Class<?>[] nullToEmpty(Class<?>[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

3.2

public static Double[] nullToEmpty(Double[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static Float[] nullToEmpty(Float[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static Integer[] nullToEmpty(Integer[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static Long[] nullToEmpty(Long[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static Object[] nullToEmpty(Object[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static <T> T[] nullToEmpty(T[] array, Class<T[]> type)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

Parameters:
  • array – The array to check for null or empty.

  • type – The class representation of the desired array.

Type parameters:

<T> – the class type.

Returns:

The same array, public static empty array if null.

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 null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static String[] nullToEmpty(String[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static long[] nullToEmpty(long[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or empty input.

Since:

2.5

public static short[] nullToEmpty(short[] array)[source]

Defensive programming technique to change a null reference to an empty one.

This method returns an empty array for a null input array.

As a memory optimizing technique an empty array passed in will be overridden with the empty public static references in this class.

Parameters:

array – The array to check for null or empty.

Returns:

The same array, public static empty array if null or 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 return null.

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 null if the input array is null.

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 return null.

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 null if the input array is null.

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 return null.

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 null if the input array is null.

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 return null.

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 null if the input array is null.

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 return null.

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 null if the input array is null.

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 return null.

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 null if the input array is null.

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 return null.

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 null if the input array is null.

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 return null.

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 null if the input array is null.

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 return null.

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 null if the input array is null.

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]

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. null will be returned if the input array is null.

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]

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. null will be returned if the input array is null.

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]

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. null will be returned if the input array is null.

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]

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. null will be returned if the input array is null.

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]

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. null will be returned if the input array is null.

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]

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. null will be returned if the input array is null.

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]

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. null will be returned if the input array is null.

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]

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. null will be returned if the input array is null.

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]

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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. null will be returned if the input array is null.

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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null input 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 null or 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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 ThreadLocalRandom as its random number generator.

Instances of ThreadLocalRandom are not cryptographically secure. For security-sensitive applications, consider using a shuffle method with a SecureRandom argument.

Parameters:

array – The array to shuffle.

See also:

Fisher-Yates shuffle algorithm

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:

Fisher-Yates shuffle algorithm

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 boolean array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive. Null array input produces null output.

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:

Arrays#copyOfRange(boolean[], int, int)

public static byte[] subarray(byte[] array, int startIndexInclusive, int endIndexExclusive)[source]

Produces a new byte array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive. Null array input produces null output.

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:

Arrays#copyOfRange(byte[], int, int)

public static char[] subarray(char[] array, int startIndexInclusive, int endIndexExclusive)[source]

Produces a new char array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive. Null array input produces null output.

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:

Arrays#copyOfRange(char[], int, int)

public static double[] subarray(double[] array, int startIndexInclusive, int endIndexExclusive)[source]

Produces a new double array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive. Null array input produces null output.

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:

Arrays#copyOfRange(double[], int, int)

public static float[] subarray(float[] array, int startIndexInclusive, int endIndexExclusive)[source]

Produces a new float array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive. Null array input produces null output.

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:

Arrays#copyOfRange(float[], int, int)

public static int[] subarray(int[] array, int startIndexInclusive, int endIndexExclusive)[source]

Produces a new int array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive. Null array input produces null output.

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:

Arrays#copyOfRange(int[], int, int)

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:

Arrays#copyOfRange(Object[], int, int)

public static long[] subarray(long[] array, int startIndexInclusive, int endIndexExclusive)[source]

Produces a new long array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive. Null array input produces null output.

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:

Arrays#copyOfRange(long[], int, int)

public static short[] subarray(short[] array, int startIndexInclusive, int endIndexExclusive)[source]

Produces a new short array containing the elements between the start and end indices.

The start index is inclusive, the end index exclusive. Null array input produces null output.

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:

Arrays#copyOfRange(short[], int, int)

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 null or 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 null or empty input array or for overflow indices. Negative indices are promoted to 0(zero). If any of the sub-arrays to swap falls outside of the given array, then the swap is stopped at the end of the array and as many as possible elements are swapped.

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 to new 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 a java.util.Map.Entry or an Array, containing at least two elements, where the first element is used as key and the second as value.

This method can be used to initialize:

// Create a Map mapping colors.
Map colorMap = ArrayUtils.toMap(new String[][] { { "RED", "#FF0000" }, { "GREEN", "#00FF00" }, { "BLUE", "#0000FF" } });

This method returns null for a null input array.

Parameters:

array – An array whose elements are either a java.util.Map.Entry or an Array containing at least two elements, may be null.

Returns:

A Map that 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.Entry and an Array.

public static Boolean[] toObject(boolean[] array)[source]

Converts an array of primitive booleans to objects.

This method returns null for a null input array.

Parameters:

array – A boolean array.

Returns:

A Boolean array, null if null array input.

public static Byte[] toObject(byte[] array)[source]

Converts an array of primitive bytes to objects.

This method returns null for a null input array.

Parameters:

array – A byte array.

Returns:

A Byte array, null if null array input.

public static Character[] toObject(char[] array)[source]

Converts an array of primitive chars to objects.

This method returns null for a null input array.

Parameters:

array – A char array.

Returns:

A Character array, null if null array input.

public static Double[] toObject(double[] array)[source]

Converts an array of primitive doubles to objects.

This method returns null for a null input array.

Parameters:

array – A double array.

Returns:

A Double array, null if null array input.

public static Float[] toObject(float[] array)[source]

Converts an array of primitive floats to objects.

This method returns null for a null input array.

Parameters:

array – A float array.

Returns:

A Float array, null if null array input.

public static Integer[] toObject(int[] array)[source]

Converts an array of primitive ints to objects.

This method returns null for a null input array.

Parameters:

array – An int array.

Returns:

An Integer array, null if null array input.

public static Long[] toObject(long[] array)[source]

Converts an array of primitive longs to objects.

This method returns null for a null input array.

Parameters:

array – A long array.

Returns:

A Long array, null if null array input.

public static Short[] toObject(short[] array)[source]

Converts an array of primitive shorts to objects.

This method returns null for a null input array.

Parameters:

array – A short array.

Returns:

A Short array, null if null array input.

public static boolean[] toPrimitive(Boolean[] array)[source]

Converts an array of object Booleans to primitives.

This method returns null for a null input array.

Null array elements map to false, like Boolean.parseBoolean(null) and its callers return false.

Parameters:

array – A Boolean array, may be null.

Returns:

A boolean array, null if 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 null for a null input array.

Parameters:
  • array – A Boolean array, may be null.

  • valueForNull – The value to insert if null found.

Returns:

A boolean array, null if null array input.

public static byte[] toPrimitive(Byte[] array)[source]

Converts an array of object Bytes to primitives.

This method returns null for a null input array.

Parameters:

array – A Byte array, may be null.

Returns:

A byte array, null if 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 null for a null input array.

Parameters:
  • array – A Byte array, may be null.

  • valueForNull – The value to insert if null found.

Returns:

A byte array, null if null array input.

public static char[] toPrimitive(Character[] array)[source]

Converts an array of object Characters to primitives.

This method returns null for a null input array.

Parameters:

array – A Character array, may be null.

Returns:

A char array, null if 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 null for a null input array.

Parameters:
  • array – A Character array, may be null.

  • valueForNull – The value to insert if null found.

Returns:

A char array, null if null array input.

public static double[] toPrimitive(Double[] array)[source]

Converts an array of object Doubles to primitives.

This method returns null for a null input array.

Parameters:

array – A Double array, may be null.

Returns:

A double array, null if 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 null for a null input array.

Parameters:
  • array – A Double array, may be null.

  • valueForNull – The value to insert if null found.

Returns:

A double array, null if null array input.

public static float[] toPrimitive(Float[] array)[source]

Converts an array of object Floats to primitives.

This method returns null for a null input array.

Parameters:

array – A Float array, may be null.

Returns:

A float array, null if 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 null for a null input array.

Parameters:
  • array – A Float array, may be null.

  • valueForNull – The value to insert if null found.

Returns:

A float array, null if null array input.

public static int[] toPrimitive(Integer[] array)[source]

Converts an array of object Integers to primitives.

This method returns null for a null input array.

Parameters:

array – A Integer array, may be null.

Returns:

An int array, null if 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 null for a null input array.

Parameters:
  • array – A Integer array, may be null.

  • valueForNull – The value to insert if null found.

Returns:

An int array, null if null array input.

public static long[] toPrimitive(Long[] array)[source]

Converts an array of object Longs to primitives.

This method returns null for a null input array.

Parameters:

array – A Long array, may be null.

Returns:

A long array, null if 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 null for a null input array.

Parameters:
  • array – A Long array, may be null.

  • valueForNull – The value to insert if null found.

Returns:

A long array, null if 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 null for a null input 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 null for a null input array.

Parameters:

array – A Short array, may be null.

Returns:

A byte array, null if 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 null for a null input array.

Parameters:
  • array – A Short array, may be null.

  • valueForNull – The value to insert if null found.

Returns:

A byte array, null if null array input.

public static String toString(Object array)[source]

Outputs an array as a String, treating null as an empty array.

Multi-dimensional arrays are handled correctly, including multi-dimensional primitive arrays.

The format is that of Java source code, for example {a,b}.

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 null for a null input array.

Parameters:

array – The Object[] to be processed, may be null.

Returns:

String[] of the same size as the source with its element’s string representation, null if 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 null elements.

This method returns null for a null input array.

Parameters:
  • array – The Object[] to be processed, may be null.

  • valueForNullElements – The value to insert if null is found.

Returns:

A String array, null if null array input.

Since:

3.6