public final class ArrayUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
add(T[] array,
T element)
Adds an element to the given array
|
static java.lang.Boolean[] |
box(boolean[] booleans)
Converts a boolean[] to a Boolean array.
|
static java.lang.Byte[] |
box(byte[] bytes)
Converts a byte[] to a Byte array.
|
static java.lang.Character[] |
box(char[] chars)
Converts a char[] to a Character array.
|
static java.lang.Double[] |
box(double[] doubles)
Converts a double[] to a Double array.
|
static java.lang.Float[] |
box(float[] floats)
Converts a float[] to a Float array.
|
static java.lang.Integer[] |
box(int[] ints)
Converts a int[] to an Integer array.
|
static java.lang.Long[] |
box(long[] longs)
Converts a long[] to a Long array.
|
static java.lang.Short[] |
box(short[] shorts)
Converts a short[] to a Short array.
|
static java.util.List<java.lang.Boolean> |
boxBools(boolean[] booleans)
Converts a boolean[] to a Boolean list.
|
static java.util.List<java.lang.Byte> |
boxBytes(byte[] bytes)
Converts a byte[] to a Byte list.
|
static java.util.List<java.lang.Character> |
boxChars(char[] chars)
Converts a char[] to a Character list.
|
static java.util.List<java.lang.Double> |
boxDoubles(double[] doubles)
Converts a double[] to a Double list.
|
static java.util.List<java.lang.Float> |
boxFloats(float[] floats)
Converts a float[] to a Float list.
|
static java.util.List<java.lang.Integer> |
boxInts(int[] ints)
Converts a int[] to an Integer list.
|
static java.util.List<java.lang.Long> |
boxLongs(long[] longs)
Converts a long[] to a Long list.
|
static java.util.List<java.lang.Short> |
boxShorts(short[] shorts)
Converts a short[] to a Short list.
|
static <T> void |
clear(T[] array)
Clears an array with the default Type T value, i.e.
|
static <T> void |
clear(T[] array,
T element)
Clears an array with the provided value
|
static <T> T[] |
clone(T[] array)
Clones the given array
|
static <T> T[] |
copy(T[] array)
Clones the given array
|
static int |
count(java.lang.Object array)
Returns the length of any array (primitive or object array).
|
static <T> T[] |
create(java.lang.Class<?> componentType,
int size)
Creates a generic array
|
static <T> T[] |
create(T value,
int length)
Creates a 1-dimensional array populated with the specified element in all places
|
static <T> T[][] |
create(T value,
int lengthX,
int lengthY)
Creates a 2-dimensional array populated with the specified element's reference in all places
|
static <T> T[] |
deepClone(T[] array)
Clones the given array, by invoking clone on all non-null elements of the array.
|
static int |
getDimensions(java.lang.Object array)
Returns the dimensions of the provided object.
|
static PrimitiveArrayType |
getType(java.lang.Object array)
Returns true if the provided object refers to a primitive array, e.g.
|
static <T> T[] |
join(java.lang.Iterable<T[]> arrays)
Joins two or more arrays in the order they were provided.
|
static <T> T[] |
join(T[] first,
T[] second)
Joins two arrays in the order they were provided.
|
static <T> T[] |
prepend(T[] array,
T element)
Adds an element to the given array, at position 0
|
static <T> T[] |
remove(T[] array,
int index)
Removes the element at the given position from the given array.
|
static <T> T[] |
remove(T[] array,
T element)
Removes the first encounter of element from the given array, returning an new array if found.
|
static <T> T[] |
removeAll(T[] array,
T element)
Removes all occurences of element from the given array, returning an new array if found.
|
static <T> T[] |
resize(T[] array,
int length)
Re-sizes an array to the specified size.
|
static <T> T[] |
reverse(T[] array)
Reverses an array (in place)
|
static <T> T[] |
reverseCopy(T[] array)
Reverses an array (creates a new copy)
|
static <T> T[] |
subArray(T[] array,
int startIndex,
int endIndex)
Returns a sub-array of the given array
|
static <T> void |
toCollection(T[] from,
java.util.Collection<T> to)
Puts all elements from an array to a collection
|
static <T> ReifiedLinkedList<T> |
toLinkedList(T[] array)
Returns the given array as a LinkedList (a class operating as a Queue or Stack).
|
static <T> ReifiedList<T> |
toList(T[] array)
Converts an array to a list.
|
static <T extends java.lang.Comparable<T>> |
toSortedList(T[] array)
Returns the given array as a PriorityQueue.
|
static <T extends java.lang.Comparable<T>> |
toSortedList(T[] array,
java.util.Comparator<? super T> comparator)
Returns the given array as a PriorityQueue.
|
static boolean[] |
unbox(java.lang.Boolean[] booleans)
Converts a Boolean sequence to primitive boolean[].
|
static byte[] |
unbox(java.lang.Byte[] bytes)
Converts a Byte sequence to primitive byte[].
|
static char[] |
unbox(java.lang.Character[] characters)
Converts a Character sequence to primitive char[].
|
static double[] |
unbox(java.lang.Double[] doubles)
Converts a Double sequence to primitive double[].
|
static float[] |
unbox(java.lang.Float[] longs)
Converts a Float sequence to primitive float[].
|
static int[] |
unbox(java.lang.Integer[] ints)
Converts a Integer sequence to primitive int[].
|
static long[] |
unbox(java.lang.Long[] longs)
Converts a Long sequence to primitive long[].
|
static short[] |
unbox(java.lang.Short[] shorts)
Converts a Short sequence to primitive short[].
|
static boolean[] |
unboxBools(java.lang.Iterable<java.lang.Boolean> booleans)
Converts a Boolean sequence to primitive boolean[].
|
static byte[] |
unboxBytes(java.lang.Iterable<java.lang.Byte> bytes)
Converts a Byte sequence to primitive byte[].
|
static char[] |
unboxChars(java.lang.Iterable<java.lang.Character> characters)
Converts a Character sequence to primitive char[].
|
static double[] |
unboxDoubles(java.lang.Iterable<java.lang.Double> doubles)
Converts a Double sequence to primitive double[].
|
static float[] |
unboxFloats(java.lang.Iterable<java.lang.Float> floats)
Converts a Float sequence to primitive float[].
|
static int[] |
unboxInts(java.lang.Iterable<java.lang.Integer> ints)
Converts a Integer sequence to primitive int[].
|
static long[] |
unboxLongs(java.lang.Iterable<java.lang.Long> longs)
Converts a Long sequence to primitive long[].
|
static short[] |
unboxShorts(java.lang.Iterable<java.lang.Short> shorts)
Converts a Short sequence to primitive short[].
|
public static <T> T[] add(T[] array, T element)
java.lang.NullPointerException
- Array is null.public static java.lang.Boolean[] box(boolean[] booleans)
java.lang.NullPointerException
- An argument is nullpublic static java.lang.Byte[] box(byte[] bytes)
java.lang.NullPointerException
- An argument is nullpublic static java.lang.Character[] box(char[] chars)
java.lang.NullPointerException
- An argument is nullpublic static java.lang.Short[] box(short[] shorts)
java.lang.NullPointerException
- An argument is nullpublic static java.lang.Integer[] box(int[] ints)
java.lang.NullPointerException
- An argument is nullpublic static java.lang.Long[] box(long[] longs)
java.lang.NullPointerException
- An argument is nullpublic static java.lang.Float[] box(float[] floats)
java.lang.NullPointerException
- An argument is nullpublic static java.lang.Double[] box(double[] doubles)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<java.lang.Boolean> boxBools(boolean[] booleans)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<java.lang.Byte> boxBytes(byte[] bytes)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<java.lang.Character> boxChars(char[] chars)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<java.lang.Short> boxShorts(short[] shorts)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<java.lang.Integer> boxInts(int[] ints)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<java.lang.Long> boxLongs(long[] longs)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<java.lang.Float> boxFloats(float[] floats)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<java.lang.Double> boxDoubles(double[] doubles)
java.lang.NullPointerException
- An argument is nullpublic static <T> void clear(T[] array)
java.lang.NullPointerException
- Array is null.public static <T> void clear(T[] array, T element)
java.lang.NullPointerException
- Array is null.public static <T> T[] clone(T[] array)
java.lang.NullPointerException
- Array is null.public static <T> T[] copy(T[] array)
java.lang.NullPointerException
- Array is null.public static int count(java.lang.Object array)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- The argument is not a primitive or object arraypublic static <T> T[] create(java.lang.Class<?> componentType, int size)
java.lang.NullPointerException
- An argument is nulljava.lang.IllegalArgumentException
- If componentType is Void.TYPE
java.lang.ClassCastException
- An invalid type parameter was specifiedjava.lang.NegativeArraySizeException
- If the specified size is negativepublic static <T> T[] create(T value, int length)
java.lang.NullPointerException
- Value is null.java.lang.IllegalArgumentException
- Value is null, or length is out of range.java.lang.OutOfMemoryError
- No enough memory to allocate arraypublic static <T> T[][] create(T value, int lengthX, int lengthY)
java.lang.NullPointerException
- The value is nulljava.lang.IllegalArgumentException
- A dimension is out of range.java.lang.OutOfMemoryError
- No enough memory to allocate arraypublic static <T> T[] deepClone(T[] array)
java.lang.IllegalArgumentException
- The underlying clone() method is inaccessible due to Java access control, or an invocation error
occurredjava.lang.NullPointerException
- Array is null.public static PrimitiveArrayType getType(java.lang.Object array)
java.lang.NullPointerException
- An argument is nulljava.lang.IllegalArgumentException
- The argument is not a primitive or object arraypublic static int getDimensions(java.lang.Object array)
java.lang.NullPointerException
- An argument is nulljava.lang.IllegalArgumentException
- The argument is not a primitive or object arraypublic static <T> T[] join(T[] first, T[] second)
java.lang.NullPointerException
- Array collection is nulljava.lang.IllegalStateException
- Component type cannot be determined.public static <T> T[] join(java.lang.Iterable<T[]> arrays)
java.lang.NullPointerException
- Array collection is nulljava.lang.IllegalStateException
- Component type cannot be determined.public static <T> T[] prepend(T[] array, T element)
java.lang.NullPointerException
- Array is null.public static <T> T[] remove(T[] array, T element)
java.lang.NullPointerException
- Array is null.public static <T> T[] removeAll(T[] array, T element)
java.lang.NullPointerException
- Array is null.public static <T> T[] remove(T[] array, int index)
java.lang.NullPointerException
- Array is nulljava.lang.IndexOutOfBoundsException
- Index is out of rangepublic static <T> T[] resize(T[] array, int length)
java.lang.NullPointerException
- Array is nulljava.lang.IllegalArgumentException
- Length is out of rangepublic static <T> T[] reverse(T[] array)
java.lang.NullPointerException
- Array is null.public static <T> T[] reverseCopy(T[] array)
java.lang.NullPointerException
- Array is null.public static <T> T[] subArray(T[] array, int startIndex, int endIndex)
java.lang.NullPointerException
- Array is null.java.lang.IndexOutOfBoundsException
- Start index / end index are out of range.public static <T> void toCollection(T[] from, java.util.Collection<T> to)
java.lang.NullPointerException
- An argument is null.public static <T> ReifiedList<T> toList(T[] array)
java.lang.NullPointerException
- The array is null.public static <T extends java.lang.Comparable<T>> SortedList<T> toSortedList(T[] array)
java.lang.NullPointerException
- The array is null.public static <T extends java.lang.Comparable<T>> SortedList<T> toSortedList(T[] array, java.util.Comparator<? super T> comparator)
java.lang.NullPointerException
- The array is null.public static <T> ReifiedLinkedList<T> toLinkedList(T[] array)
java.lang.NullPointerException
- The array is null.public static boolean[] unboxBools(java.lang.Iterable<java.lang.Boolean> booleans)
java.lang.NullPointerException
- An argument is nullpublic static boolean[] unbox(java.lang.Boolean[] booleans)
java.lang.NullPointerException
- An argument is nullpublic static byte[] unboxBytes(java.lang.Iterable<java.lang.Byte> bytes)
java.lang.NullPointerException
- An argument is nullpublic static byte[] unbox(java.lang.Byte[] bytes)
java.lang.NullPointerException
- An argument is nullpublic static char[] unboxChars(java.lang.Iterable<java.lang.Character> characters)
java.lang.NullPointerException
- An argument is nullpublic static char[] unbox(java.lang.Character[] characters)
java.lang.NullPointerException
- An argument is nullpublic static short[] unboxShorts(java.lang.Iterable<java.lang.Short> shorts)
java.lang.NullPointerException
- An argument is nullpublic static short[] unbox(java.lang.Short[] shorts)
java.lang.NullPointerException
- An argument is nullpublic static int[] unboxInts(java.lang.Iterable<java.lang.Integer> ints)
java.lang.NullPointerException
- An argument is nullpublic static int[] unbox(java.lang.Integer[] ints)
java.lang.NullPointerException
- An argument is nullpublic static long[] unboxLongs(java.lang.Iterable<java.lang.Long> longs)
java.lang.NullPointerException
- An argument is nullpublic static long[] unbox(java.lang.Long[] longs)
java.lang.NullPointerException
- An argument is nullpublic static float[] unboxFloats(java.lang.Iterable<java.lang.Float> floats)
java.lang.NullPointerException
- An argument is nullpublic static float[] unbox(java.lang.Float[] longs)
java.lang.NullPointerException
- An argument is nullpublic static double[] unboxDoubles(java.lang.Iterable<java.lang.Double> doubles)
java.lang.NullPointerException
- An argument is nullpublic static double[] unbox(java.lang.Double[] doubles)
java.lang.NullPointerException
- An argument is null