public final class ArrayUtil extends Object
In all cases the array being mutated is assumed to be full.
In all cases reference equality is used.
Modifier and Type | Field and Description |
---|---|
static boolean[] |
EMPTY_BOOLEAN_ARRAY
Empty boolean array.
|
static byte[] |
EMPTY_BYTE_ARRAY
Empty byte array.
|
static char[] |
EMPTY_CHAR_ARRAY
Empty char array.
|
static double[] |
EMPTY_DOUBLE_ARRAY
Empty double array.
|
static float[] |
EMPTY_FLOAT_ARRAY
Empty float array.
|
static int[] |
EMPTY_INT_ARRAY
Empty int array.
|
static long[] |
EMPTY_LONG_ARRAY
Empty boolean array.
|
static Object[] |
EMPTY_OBJECT_ARRAY
Empty Object array.
|
static short[] |
EMPTY_SHORT_ARRAY
Empty short array.
|
static String[] |
EMPTY_STRING_ARRAY
Empty String array.
|
static int |
MAX_CAPACITY
Maximum capacity to which an array can grow.
|
static int |
UNKNOWN_INDEX
Constant indicating an invalid/unknown array index.
|
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
add(T[] oldElements,
T elementToAdd)
Add an element to an array resulting in a new array.
|
static <T> T[] |
ensureCapacity(T[] oldElements,
int requiredLength)
Ensure an array has the required capacity.
|
static <T> T[] |
newArray(T[] oldElements,
int length)
Allocate a new array of the same type as another array.
|
static <T> T[] |
remove(T[] oldElements,
int index)
Remove an element from an array resulting in a new array if the index was inside the array otherwise the old
array.
|
static <T> T[] |
remove(T[] oldElements,
T elementToRemove)
Remove an element from an array resulting in a new array if the element was found otherwise the old array.
|
public static final int UNKNOWN_INDEX
public static final boolean[] EMPTY_BOOLEAN_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
public static final char[] EMPTY_CHAR_ARRAY
public static final short[] EMPTY_SHORT_ARRAY
public static final int[] EMPTY_INT_ARRAY
public static final float[] EMPTY_FLOAT_ARRAY
public static final long[] EMPTY_LONG_ARRAY
public static final double[] EMPTY_DOUBLE_ARRAY
public static final Object[] EMPTY_OBJECT_ARRAY
public static final String[] EMPTY_STRING_ARRAY
public static final int MAX_CAPACITY
public static <T> T[] add(T[] oldElements, T elementToAdd)
T
- type of the array.oldElements
- to have the new element added.elementToAdd
- for the new array.public static <T> T[] remove(T[] oldElements, T elementToRemove)
Returns its input parameter if the element to remove isn't a member.
T
- type of the array.oldElements
- to have the element removed from.elementToRemove
- being searched for by identity semantics.public static <T> T[] remove(T[] oldElements, int index)
Returns the old elements array if the index isn't inside the array.
T
- type of the array.oldElements
- to have the element removed from.index
- to remove the element at.public static <T> T[] newArray(T[] oldElements, int length)
T
- type of the array.oldElements
- on which the new array is based.length
- of the new array.public static <T> T[] ensureCapacity(T[] oldElements, int requiredLength)
T
- type of the array.oldElements
- to ensure that are long enough.requiredLength
- to ensure.Copyright © 2014-2021 Real Logic Limited. All Rights Reserved.