Constructor and Description |
---|
ArrayUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
asArray(T... elements)
Returns the given varargs
element as an array. |
static <T> T[] |
defaultIfEmpty(T[] array,
T[] defaultArray)
Returns the given
array if not null or empty, otherwise returns the defaultArray . |
static <T> T |
getFirst(T[] array)
Null-safe method to return the first element in the array or null
if the array is null or empty.
|
static <T> T |
getFirst(T[] array,
T defaultValue)
Null-safe method to return the first element in the array or the
defaultValue
if the array is null or empty. |
static Object[] |
insert(Object[] originalArray,
int position,
Object element)
Insert an element into the given array at position (index).
|
static boolean |
isEmpty(Object[] array)
Determines whether the given array is empty or not.
|
static boolean |
isNotEmpty(Object[] array)
Determines whether the given array is empty or not.
|
static int |
length(Object[] array)
Null-safe operation to determine an array's length.
|
static <T> T[] |
nullSafeArray(T[] array,
Class<T> componentType)
Null-safe, empty array operation returning the given object array if not null or an empty object array
if the array argument is null.
|
static Object[] |
remove(Object[] originalArray,
int position)
Remove an element from the given array at position (index).
|
static <T extends Comparable<T>> |
sort(T[] array)
Sort the array of elements according to the elements natural ordering.
|
@SafeVarargs public static <T> T[] asArray(T... elements)
element
as an array.T
- Class type of the elements.elements
- variable list of arguments to return as an array.elements
.public static <T> T[] defaultIfEmpty(T[] array, T[] defaultArray)
array
if not null or empty, otherwise returns the defaultArray
.T
- Class
type of the array elements.array
- array to evaluate.defaultArray
- array to return if the given array
is null or empty.array
if not null or empty otherwise return the defaultArray
.public static <T> T getFirst(T[] array)
T
- Class type of the array elements.array
- the array from which to extract the first element.getFirst(Object[], Object)
public static <T> T getFirst(T[] array, T defaultValue)
defaultValue
if the array is null or empty.T
- Class type of the array elements.array
- the array from which to extract the first element.defaultValue
- value to return if the array is null or empty.defaultValue
if the array is null or empty.getFirst(Object[], Object)
public static Object[] insert(Object[] originalArray, int position, Object element)
originalArray
- the array in which to insert the element.position
- an integer index (position) at which to insert the element in the array.element
- the element to insert into the array.System.arraycopy(Object, int, Object, int, int)
,
Array.newInstance(Class, int)
public static boolean isEmpty(Object[] array)
array
- the array to evaluate for emptiness.length(Object...)
public static boolean isNotEmpty(Object[] array)
array
- the array to evaluate for emptiness.isEmpty(Object[])
public static int length(Object[] array)
array
- the array to determine it's length.public static <T> T[] nullSafeArray(T[] array, Class<T> componentType)
T
- Class type of the array elements.array
- array of objects on which a null check is performed.componentType
- Class type of the array elements.Array.newInstance(Class, int)
public static Object[] remove(Object[] originalArray, int position)
originalArray
- the array from which to remove the element.position
- the integer index (position) indicating the element to remove from the array.System.arraycopy(Object, int, Object, int, int)
,
Array.newInstance(Class, int)
public static <T extends Comparable<T>> T[] sort(T[] array)
T
- Comparable
class type of the array elements.array
- array of elements to sort.Arrays.sort(Object[])
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.