public class ArrayUtils extends Object
Array utils.
| 构造器和说明 |
|---|
ArrayUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> T[] |
append(T[] array,
T... elements)
Append elements to array and return a new array.
|
static <T> boolean |
contains(T[] array,
T target)
Whether
target is contained in array. |
static <T> T |
get(T[] array,
int index)
Get element from an array, return null if the array is null or index out of bounds.
|
static <T> T |
getFirstNotNull(T... array)
Get first a not null element from an array.
|
static boolean |
isEmpty(Object[] array)
Whether array is null or empty.
|
static <T,U> boolean |
isEquals(T[] array1,
U[] array2)
Compare two arrays and return true if they are equal by
Objects.equals(Object, Object). |
static <T,U> boolean |
isEquals(T[] array1,
U[] array2,
BiPredicate<T,U> predicate)
Compare two arrays and return true if they are equal by
predicate. |
static boolean |
isNotEmpty(Object[] array)
Whether array is not null and not empty.
|
static String |
join(String[] array,
String delimiter)
Join array to string with delimiter.
|
static <T> String |
join(T[] array,
Function<T,String> mapper,
String delimiter)
Join array to string with delimiter.
|
static <T> int |
length(T[] array)
Get length of an array, return 0 if the array is null.
|
static <T> Stream<T> |
stream(T[] array)
Get stream of array, return empty stream if array is null.
|
@SafeVarargs public static <T> T getFirstNotNull(T... array)
Get first a not null element from an array.
T - element typearray - array@SafeVarargs public static <T> T[] append(T[] array, T... elements)
Append elements to array and return a new array.
T - element typearray - array to appendelements - elementselements directlypublic static boolean isEmpty(Object[] array)
Whether array is null or empty.
array - arraypublic static boolean isNotEmpty(Object[] array)
Whether array is not null and not empty.
array - arraypublic static <T> String join(T[] array, Function<T,String> mapper, String delimiter)
Join array to string with delimiter.
T - element typearray - arraymapper - mapper, map element to stringdelimiter - delimiterpublic static String join(String[] array, String delimiter)
Join array to string with delimiter.
array - array of stringdelimiter - delimiterpublic static <T> boolean contains(T[] array,
T target)
Whether target is contained in array.
T - type of arrayarray - array, null returns falsetarget - targettarget is contained in arraypublic static <T> Stream<T> stream(T[] array)
Get stream of array, return empty stream if array is null.
T - type of arrayarray - arraypublic static <T> T get(T[] array,
int index)
Get element from an array, return null if the array is null or index out of bounds.
T - type of arrayarray - arrayindex - indexpublic static <T> int length(T[] array)
Get length of an array, return 0 if the array is null.
T - type of arrayarray - arraypublic static <T,U> boolean isEquals(T[] array1,
U[] array2)
Compare two arrays and return true if they are equal by Objects.equals(Object, Object).
T - type of array1U - type of array2array1 - array1array2 - array2public static <T,U> boolean isEquals(T[] array1,
U[] array2,
BiPredicate<T,U> predicate)
Compare two arrays and return true if they are equal by predicate.
T - type of array1U - type of array2array1 - array1array2 - array2predicate - predicate to compareCopyright © 2024. All rights reserved.