public final class ArrayUtils extends Object
The ArrayUtils
class provides utility methods for array
handling.
Modifier and Type | Method and Description |
---|---|
static boolean[] |
concat(boolean[]... arrays)
Applies to: boolean arrays
|
static boolean[] |
concat(boolean[] array,
boolean elem)
Applies to: boolean array and boolean element
|
static byte[] |
concat(byte[]... arrays)
Applies to: byte arrays
|
static byte[] |
concat(byte[] array,
byte elem)
Applies to: byte array and byte element
|
static char[] |
concat(char[]... arrays)
Applies to: char arrays
|
static char[] |
concat(char[] array,
char elem)
Applies to: char array and char element
|
static <T> T[] |
concat(Class<T> type,
T[]... arrays)
Applies to: T arrays
|
static <T> T[] |
concat(Class<T> type,
T[] array,
T elem)
Applies to: T array and T element
|
static double[] |
concat(double[]... arrays)
Applies to: double arrays
|
static double[] |
concat(double[] array,
double elem)
Applies to: double array and double element
|
static float[] |
concat(float[]... arrays)
Applies to: float arrays
|
static float[] |
concat(float[] array,
float elem)
Applies to: float array and float element
|
static int[] |
concat(int[]... arrays)
Applies to: int arrays
|
static int[] |
concat(int[] array,
int elem)
Applies to: int array and int element
|
static long[] |
concat(long[]... arrays)
Applies to: long arrays
|
static long[] |
concat(long[] array,
long elem)
Applies to: long array and long element
|
static short[] |
concat(short[]... arrays)
Applies to: short arrays
|
static short[] |
concat(short[] array,
short elem)
Applies to: short array and short element
|
static boolean |
contains(boolean[] array,
boolean value)
Applies to: boolean array
|
static boolean |
contains(byte[] array,
byte value)
Applies to: byte array
|
static boolean |
contains(char[] array,
char value)
Applies to: char array
|
static boolean |
contains(double[] array,
double value)
Applies to: double array
|
static boolean |
contains(float[] array,
float value)
Applies to: float array
|
static boolean |
contains(int[] array,
int value)
Applies to: int array
|
static boolean |
contains(long[] array,
long value)
Applies to: long array
|
static boolean |
contains(Object[] array,
Object value)
Applies to: Object array
|
static boolean |
contains(short[] array,
short value)
Applies to: short array
|
static <T> boolean |
contains(T[] array,
T value,
Comparer<T> c)
Applies to: T array
|
static byte[] |
copy(byte[] data)
Applies to: byte array
|
static boolean[] |
copyOf(boolean[] data)
Applies to: boolean array
|
static char[] |
copyOf(char[] data)
Applies to: char array
|
static double[] |
copyOf(double[] data)
Applies to: double array
|
static float[] |
copyOf(float[] data)
Applies to: float array
|
static int[] |
copyOf(int[] data)
Applies to: int array
|
static long[] |
copyOf(long[] data)
Applies to: long array
|
static short[] |
copyOf(short[] data)
Applies to: short array
|
static <T> T[] |
copyOf(T[] data)
Applies to: T array
|
static <T extends Comparable<?>> |
equals(T[] array1,
T[] array2)
Checks if the two arrays are equal.
The arrays are sorted before comparison, if they are not null . |
static <T> Iterable<T> |
getIterable(T[] array)
Returns a
Iterable for the given array . |
static <T> Iterable<T> |
getIterable(T[] array,
int offset,
int length)
Returns a
Iterable for the given array . |
static <T> Iterator<T> |
getIterator(T[] array)
Returns a
Iterator for the given array . |
static <T> Iterator<T> |
getIterator(T[] array,
int offset,
int length)
Returns a
Iterator for the given array . |
static int |
indexOf(boolean[] array,
boolean value)
Applies to: boolean array
|
static int |
indexOf(byte[] array,
byte value)
Applies to: byte array
|
static int |
indexOf(char[] array,
char value)
Applies to: char array
|
static int |
indexOf(double[] array,
double value)
Applies to: double array
|
static int |
indexOf(float[] array,
float value)
Applies to: float array
|
static int |
indexOf(int[] array,
int value)
Applies to: int array
|
static int |
indexOf(long[] array,
long value)
Applies to: long array
|
static int |
indexOf(Object[] array,
Object value)
Applies to: Object array
|
static int |
indexOf(short[] array,
short value)
Applies to: short array
|
static <T> int |
indexOf(T[] array,
T value,
Comparer<T> c)
Applies to: T array
|
static boolean[] |
remove(boolean[] array,
int index)
Applies to: boolean arrays
|
static byte[] |
remove(byte[] array,
int index)
Applies to: byte arrays
|
static char[] |
remove(char[] array,
int index)
Applies to: char arrays
|
static <T> T[] |
remove(Class<T> type,
T[] array,
int index)
Applies to: T arrays
|
static double[] |
remove(double[] array,
int index)
Applies to: double arrays
|
static float[] |
remove(float[] array,
int index)
Applies to: float arrays
|
static int[] |
remove(int[] array,
int index)
Applies to: int arrays
|
static long[] |
remove(long[] array,
int index)
Applies to: long arrays
|
static short[] |
remove(short[] array,
int index)
Applies to: short arrays
|
static <E extends Enum<E>> |
sortByName(E[] array)
Sorts the given
array of Enum s by name. |
static boolean[] |
unwrap(Boolean[] wrapper)
Converts a array of wrapped
Boolean s to a primitive boolean
array. |
static byte[] |
unwrap(Byte[] wrapper)
Converts a array of wrapped
Byte s to a primitive byte array. |
static char[] |
unwrap(Character[] wrapper)
Converts a array of wrapped
Character s to a primitive char array. |
static int[] |
unwrap(Integer[] wrapper)
Converts a array of wrapped
Integer s to a primitive int array. |
static long[] |
unwrap(Long[] wrapper)
Converts a array of wrapped
Long s to a primitive long array. |
static short[] |
unwrap(Short[] wrapper)
Converts a array of wrapped
Short s to a primitive short array. |
public static <T extends Comparable<?>> boolean equals(T[] array1, T[] array2) throws NullPointerException
null
.T
- type of the array to comparearray1
- an array or null
array2
- an array or null
true
if and only if the arrays have the same length
and the array's elements are equal, false
otherwiseNullPointerException
- if an element of an array is null
public static boolean contains(Object[] array, Object value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(Object[] array, Object value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static boolean contains(boolean[] array, boolean value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(boolean[] array, boolean value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static boolean contains(char[] array, char value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(char[] array, char value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static boolean contains(byte[] array, byte value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(byte[] array, byte value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static boolean contains(short[] array, short value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(short[] array, short value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static boolean contains(int[] array, int value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(int[] array, int value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static boolean contains(long[] array, long value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(long[] array, long value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static boolean contains(float[] array, float value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(float[] array, float value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static boolean contains(double[] array, double value)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
array
- to search invalue
- element whose presence in the specified array
is
to be testedarray
contains the specified
elementpublic static int indexOf(double[] array, double value)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
array
- to search invalue
- element to search forarray
, or -1 if the given array
does not contain the elementpublic static <T> boolean contains(T[] array, T value, Comparer<T> c)
Returns true if the specified array
contains the
specified value
. More formally, returns true if and
only if the specified array
contains at least one element
value.
public static <T> int indexOf(T[] array, T value, Comparer<T> c)
Returns the index of the first occurrence of the specified element
value
in the given array, or -1 if the given
array
does not contain the element value
.
public static <T> T[] copyOf(T[] data)
Creates a (defensive) copy of the given array
.
T
- type of the array to copydata
- array
to copyarray
.public static boolean[] copyOf(boolean[] data)
Creates a (defensive) copy of the given array
.
data
- array
to copyarray
.public static char[] copyOf(char[] data)
Creates a (defensive) copy of the given array
.
data
- array
to copyarray
.public static byte[] copy(byte[] data)
Creates a (defensive) copy of the given array
.
data
- array
to copyarray
.public static short[] copyOf(short[] data)
Creates a (defensive) copy of the given array
.
data
- array
to copyarray
.public static int[] copyOf(int[] data)
Creates a (defensive) copy of the given array
.
data
- array
to copyarray
.public static long[] copyOf(long[] data)
Creates a (defensive) copy of the given array
.
data
- array
to copyarray
.public static float[] copyOf(float[] data)
Creates a (defensive) copy of the given array
.
data
- array
to copyarray
.public static double[] copyOf(double[] data)
Creates a (defensive) copy of the given array
.
data
- array
to copyarray
.public static <T> T[] concat(Class<T> type, T[] array, T elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
T
- type of the array's elementstype
- class of the array's elementsarray
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static boolean[] concat(boolean[] array, boolean elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
array
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static char[] concat(char[] array, char elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
array
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static byte[] concat(byte[] array, byte elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
array
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static short[] concat(short[] array, short elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
array
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static int[] concat(int[] array, int elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
array
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static long[] concat(long[] array, long elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
array
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static float[] concat(float[] array, float elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
array
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static double[] concat(double[] array, double elem)
Concatenates the given array
with the given element. A new
array is returned that contains all elements of the given
array
and as last element the given element
elem
. The length of the returned array will be
givenArray.length + 1
.
array
- array to concatenateelem
- element to concatenatearray
and as last element the given element
elem
.public static <T> T[] concat(Class<T> type, T[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
T
- type of the array elementstype
- class of the array elementsarrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static boolean[] concat(boolean[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
arrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static char[] concat(char[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
arrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static byte[] concat(byte[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
arrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static short[] concat(short[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
arrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static int[] concat(int[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
arrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static long[] concat(long[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
arrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static float[] concat(float[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
arrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static double[] concat(double[]... arrays)
Concatenates the given arrays
. A new array is returned that
contains all elements of the given arrays
in the order the
arrays
were passed to the method.
arrays
- arrays to concatenatearrays
in the order the arrays
were
passed to the method.public static <T> T[] remove(Class<T> type, T[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
T
- type of the array elementstype
- class of the array elementsarray
- to remove element fromindex
- the index of the element to be removedpublic static boolean[] remove(boolean[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
array
- to remove element fromindex
- the index of the element to be removedpublic static char[] remove(char[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
array
- to remove element fromindex
- the index of the element to be removedpublic static byte[] remove(byte[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
array
- to remove element fromindex
- the index of the element to be removedpublic static short[] remove(short[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
array
- to remove element fromindex
- the index of the element to be removedpublic static int[] remove(int[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
array
- to remove element fromindex
- the index of the element to be removedpublic static long[] remove(long[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
array
- to remove element fromindex
- the index of the element to be removedpublic static float[] remove(float[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
array
- to remove element fromindex
- the index of the element to be removedpublic static double[] remove(double[] array, int index)
Removes the element at the specified position from the given
array
. Shifts any subsequent elements to the left (subtracts
one from their indices). Returns the element that was removed from the
given array
.
array
- to remove element fromindex
- the index of the element to be removedpublic static <T> Iterable<T> getIterable(T[] array)
Iterable
for the given array
.public static <T> Iterable<T> getIterable(T[] array, int offset, int length)
Iterable
for the given array
.public static <T> Iterator<T> getIterator(T[] array)
public static <T> Iterator<T> getIterator(T[] array, int offset, int length)
public static <E extends Enum<E>> void sortByName(E[] array)
array
of Enum
s by name.E
- type of the array elementsarray
- to sortEnum
,
Enum.name()
,
String.compareTo(String)
public static byte[] unwrap(Byte[] wrapper) throws NullPointerException
Byte
s to a primitive byte array.wrapper
- the wrapped array of Byte
sNullPointerException
- if wrapper itself or one element of wrapper is
null
public static short[] unwrap(Short[] wrapper) throws NullPointerException
Short
s to a primitive short array.wrapper
- the wrapped array of Short
sNullPointerException
- if wrapper itself or one element of wrapper is
null
public static int[] unwrap(Integer[] wrapper) throws NullPointerException
Integer
s to a primitive int array.wrapper
- the wrapped array of Integer
sNullPointerException
- if wrapper itself or one element of wrapper is
null
public static long[] unwrap(Long[] wrapper) throws NullPointerException
Long
s to a primitive long array.wrapper
- the wrapped array of Long
sNullPointerException
- if wrapper itself or one element of wrapper is
null
public static boolean[] unwrap(Boolean[] wrapper) throws NullPointerException
Boolean
s to a primitive boolean
array.wrapper
- the wrapped array of Boolean
sNullPointerException
- if wrapper itself or one element of wrapper is
null
public static char[] unwrap(Character[] wrapper) throws NullPointerException
Character
s to a primitive char array.wrapper
- the wrapped array of Character
sNullPointerException
- if wrapper itself or one element of wrapper is
null
Copyright © 2003–2021 XDEV Software. All rights reserved.