public final class ArrayUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
contains(Object[] array,
Object element)
Check if the specified array contains the element
|
static boolean |
containsNull(Object[] array)
Check if the specified array contains null
|
static <T> Optional<T> |
findIn(T[] array,
Predicate<T> condition)
Find value in array using the predicate condition
|
static <T> void |
forEach(T[] array,
Consumer<T> consumer)
|
static <T,E extends Exception> |
forEachThrowing(T[] array,
ThrowingConsumer<T,E> consumer)
Iterable.forEach(java.util.function.Consumer) for arrays using ThrowingConsumer |
static <T> Optional<T> |
get(T[] array,
int index)
Get element of array at the given position without risk of
ArrayIndexOutOfBoundsException |
static <T> T |
get(T[] array,
int index,
T defaultValue)
Get element of array at the given position without risk of
ArrayIndexOutOfBoundsException |
static Class<?> |
getArrayClass(Class<?> clazz)
Get array class for the specified type
|
static Class<?> |
getBaseClass(Class<?> arrayClass)
Get base class of any array, e.g.
|
static Class<?> |
getDimensionalArrayType(Class<?> type,
int dimensions)
Get dimensional array for the specified type
|
static <T> int |
getIndex(T[] array,
Predicate<T> condition)
Get index of element that pass the condition
|
static <T> int |
indexOf(T[] array,
T element)
Get index of the given element
|
static boolean |
isArray(@Nullable Object object)
Check if the given object is array
|
static boolean |
isEmpty(@Nullable Object[] array)
Checks if the specified array is null or empty
|
static <T> int |
length(T[]... arrays)
Get length of all given arrays
|
static <T> T[] |
merge(T firstElement,
T[] array,
Function<Integer,T[]> arrayFunction)
Create a new array with the given element at the first position and copy the rest of array
|
static <T> T[] |
mergeArrays(Function<Integer,T[]> arrayFunction,
T[]... arrays)
Merge arrays into one array
|
static <T> T[] |
mergeArrays(T[]... arrays)
Merge several arrays
|
static <T> T[] |
of(T... elements)
Return array of the specified elements using varargs parameter
|
public static <T> void forEach(T[] array,
Consumer<T> consumer)
T - type of arrayarray - the array to iterateconsumer - array values consumerpublic static <T,E extends Exception> void forEachThrowing(T[] array, ThrowingConsumer<T,E> consumer) throws E extends Exception
Iterable.forEach(java.util.function.Consumer) for arrays using ThrowingConsumerT - type of arrayE - type of exceptionarray - the array to iterateconsumer - array values consumer with exceptions supportE - if consumer will throw exceptionE extends Exception@SafeVarargs public static <T> T[] mergeArrays(T[]... arrays)
arrays - arrays to merge@SafeVarargs public static <T> T[] mergeArrays(Function<Integer,T[]> arrayFunction, T[]... arrays)
T - type of arraysarrayFunction - array instance supplierarrays - arrays to mergepublic static <T> T[] merge(T firstElement,
T[] array,
Function<Integer,T[]> arrayFunction)
T - type of arrayfirstElement - the element to add at the first positionarray - the array to copyarrayFunction - array instance supplier with array size as an argumentpublic static <T> Optional<T> findIn(T[] array, Predicate<T> condition)
T - type of arrayarray - the array to search incondition - the conditionpublic static boolean containsNull(Object[] array)
public static boolean contains(Object[] array, Object element)
array - the array to searchelement - the element to search for@SafeVarargs public static <T> int length(T[]... arrays)
T - type of arraysarrays - the arrays to sum uppublic static boolean isArray(@Nullable
@Nullable Object object)
object - the object to checkpublic static boolean isEmpty(@Nullable
@Nullable Object[] array)
array - the array to checkpublic static Class<?> getDimensionalArrayType(Class<?> type, int dimensions)
type - the type of the arraydimensions - the amount of dimensionspublic static Class<?> getBaseClass(Class<?> arrayClass)
arrayClass - the array classpublic static Class<?> getArrayClass(Class<?> clazz)
clazz - type of arraypublic static <T> int getIndex(T[] array,
Predicate<T> condition)
T - type of arrayarray - the array to search incondition - the condition to test elementspublic static <T> int indexOf(T[] array,
@Nullable
T element)
T - type of arrayarray - the array to search inelement - element to search forpublic static <T> Optional<T> get(T[] array, int index)
ArrayIndexOutOfBoundsExceptionT - type of the arrayarray - the array to processindex - the index of element to getpublic static <T> T get(T[] array,
int index,
T defaultValue)
ArrayIndexOutOfBoundsExceptionT - type of the arrayarray - the array to processindex - the index of element to getdefaultValue - the default value to return when there is no such an index in the array@SafeVarargs public static <T> T[] of(T... elements)
T - type of the arrayelements - elements in arrayCopyright © 2020. All rights reserved.