public final class ArrayUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static Class[] |
EMPTY_CLASS_ARRAY |
static Object[] |
EMPTY_OBJECT_ARRAY
Immutable common arrays.
|
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
addAll(T[] array1,
T[] array2)
Adds all the elements of the given arrays into a new array.
|
static <T> T[] |
getArraySubset(T[] array,
int start,
int end) |
static boolean |
isEmpty(Object array)
This is a null-safe isEmpty check.
|
static <T> T[] |
removeItem(T[] array,
int pos) |
static <T> T[] |
shallowCopy(T[] array)
Shallow copies an array of Objects
|
static int |
size(Object array)
This is a null-safe size check.
|
public static final Object[] EMPTY_OBJECT_ARRAY
public static final Class[] EMPTY_CLASS_ARRAY
public static boolean isEmpty(Object array)
return array == null || array.length == 0;
array
- array to checkpublic static int size(Object array)
return (array == null) ? 0 : array.length;
array
- array to checkpublic static <T> T[] shallowCopy(T[] array)
Shallow copies an array of Objects
The objects in the array are not cloned, thus there is no special handling for multi-dimensional arrays.
This method returns null
if null
array input.
T
- the array typearray
- the array to shallow clone, may be null
null
if null
inputpublic static <T> T[] addAll(T[] array1, T[] array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1
followed
by all of the elements array2
. When an array is returned, it is always
a new array.
ArrayUtilities.addAll(null, null) = null ArrayUtilities.addAll(array1, null) = cloned copy of array1 ArrayUtilities.addAll(null, array2) = cloned copy of array2 ArrayUtilities.addAll([], []) = [] ArrayUtilities.addAll([null], [null]) = [null, null] ArrayUtilities.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"]
T
- the array typearray1
- the first array whose elements are added to the new array, may be null
array2
- the second array whose elements are added to the new array, may be null
null
if null
array inputs.
The type of the new array is the type of the first array.public static <T> T[] removeItem(T[] array, int pos)
public static <T> T[] getArraySubset(T[] array, int start, int end)
Copyright © 2015. All rights reserved.