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 Object[] |
addAll(Object[] array1,
Object[] array2)
Adds all the elements of the given arrays into a new array.
|
static Object |
getArraySubset(Object array,
int start,
int end) |
static boolean |
isEmpty(Object array)
This is a null-safe isEmpty check.
|
static Object |
removeItem(Object array,
int pos) |
static Object[] |
shallowCopy(Object[] 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;
but gives you more flexibility, since it checks for all array
types.array
- array to checkpublic static int size(Object array)
return (array == null) ? 0 : array.length;
array
- array to checkpublic static Object[] shallowCopy(Object[] 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.
array
- the array to shallow clone, may be null
null
if null
inputpublic static Object[] addAll(Object[] array1, Object[] 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"]
array1
- 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.Copyright © 2014. All rights reserved.