public final class ArrayTools
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ArrayTools.ArrayWrapper<T>
A wrapper for arrays that provide a useful (i. e. deep)
ArrayTools.ArrayWrapper.equals(Object),
ArrayTools.ArrayWrapper.hashCode() and ArrayTools.ArrayWrapper.toString(). |
| Modifier and Type | Method and Description |
|---|---|
static <T> T[] |
after(T[] arr,
int index)
Gets an array containing all elements of the designated array after (and without) the
designated index.
|
static <T> T[] |
before(T[] arr,
int index)
Gets an array containing all elements of the designated array before (and without) the
designated index.
|
static boolean |
contains(int[] arr,
int elem)
Gets whether the designated array contains the designated integer element.
|
static <T> boolean |
contains(T[] arr,
T elem)
Gets whether the designated array contains the designated element.
|
static <T> T[] |
join(T[]... arrays)
Returns a new array of the same type as all input arrays filled with their
joined content.
|
static <T> T[] |
removeElement(T[] arr,
int index)
Removes the element at the designated index from the designated array.
|
static <T> T[] |
reverse(T[] array)
Reverses the entries in the designated array and returns the very same
array afterwards.
|
static <T> T[] |
toArray(java.util.Collection<T> coll,
java.lang.Class<T> componentType)
Returns the content of the given collection in a newly created array with
the given component type and the size of the collection.
|
static <T> T[] |
toArray(T... content)
Creates an array of the designated content.
|
static <T> java.util.List<T> |
toList(T[] array)
Returns the content of the given array in a newly created (array) list.
|
static <T> java.util.Set<T> |
toSet(T[] array)
Gets the content of the designated array in a newly created set.
|
public static <T> T[] toArray(T... content)
null behaviour depends on how the method is called,
while (T) null returns an array with a null
element, (T[]) null returns null (and no array).content - The content of the array to return.null.public static <T> T[] reverse(T[] array)
T - The type of the elements of the array to be reversed. Note that
this cannot be a simple type.array - The array to reverse the order of.public static <T> T[] join(T[]... arrays)
Lists instead.T - component type of the arraysarrays - the arrays to be joinedpublic static <T> T[] toArray(java.util.Collection<T> coll,
java.lang.Class<T> componentType)
T - coll - the collection whose elements should be copied to a new arraycomponentType - the component type of the array to be createdpublic static <T> java.util.List<T> toList(T[] array)
array - an arraypublic static <T> java.util.Set<T> toSet(T[] array)
Set.contains(Object).array - The array which to get as (Hash)Set.public static boolean contains(int[] arr,
int elem)
arr - The array which to check for whether it contains the designated integer element.elem - The integer element which to check for whether it is part of the designated array.public static <T> boolean contains(T[] arr,
T elem)
null. arr - The array which to check for whether it contains the designated element.elem - The element which to check for whether it is part of the designated array. This can
be null.public static <T> T[] removeElement(T[] arr,
int index)
arr - The array from which to remove an element.index - The index of the element which to remove.public static <T> T[] before(T[] arr,
int index)
<=0, an empty array will be
returned, if the designated index is bigger than the designated array, the array will be
returned without changes.arr - The array from which to remove elements.index - The index of the first element that is not part of the returned array.public static <T> T[] after(T[] arr,
int index)
>=arr.length, an empty array will
be returned, if the designated index is <=0, the array will be returned without
changes.arr - The array from which to remove elements.index - The index of the last element that is not part of the returned array.