@ParametersAreNonnullByDefault public final class MoreArrays extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
NO_INDEX
The index value when an element is not found in a list or array:
-1. |
| Modifier and Type | Method and Description |
|---|---|
static <T> T[] |
add(T[] array,
int index,
T element)
Adds the specified
element at the specified position in the array. |
static byte[] |
addAll(byte[] array1,
byte... array2)
Adds all
array2 at the end of the array1. |
static <T> T[] |
addAll(T[] array,
int index,
Collection<? extends T> elements)
Adds all
elements at the end of the array. |
static <T> T[] |
append(T[] array,
T element)
Adds the specified
element at the last position in the array. |
static <T> boolean |
contains(T[] array,
T value)
Checks if the
value is in the given array. |
static <T> int |
indexOf(T[] array,
T value)
Finds the index of the given
value in the array. |
static <T> int |
lastIndexOf(T[] array,
T value)
Finds the last index of the given
value in the array. |
static <T> T[] |
newArray(Class<?> type,
int length)
Creates a new array with the specified component
type and length. |
static <T> T[] |
remove(T[] array,
int index)
Removes the element at the specified
index from the specified array. |
static <T> T[] |
resize(T[] array,
int length)
Resizes the
array with the given length. |
static <T> T[] |
set(T[] array,
int index,
T value)
Sets the specified
element at the index in the array. |
static Byte[] |
toObject(byte... primitiveArray)
Converts an array of primitive types
byte to an array of Objects . |
static byte[] |
toPrimitive(Byte... boxedArray)
Converts an array of
Byte to an array of primitive types byte. |
public static final int NO_INDEX
-1.@Nonnull public static <T> T[] newArray(Class<?> type, @Nonnegative int length)
type and length.T - the type of the new arraytype - the class of the new arraylength - the length of the new arrayNullPointerException - if the type is nullIllegalArgumentException - if the length is negative@Nonnull public static <T> T[] set(T[] array, @Nonnegative int index, @Nullable T value)
element at the index in the array.
This method is similar to:
array[index] = value;
return array;
T - the component type of the arrayarray - the array to set the element toindex - the position of the objectvalue - the object to setarray containing the existing elements and the new element@Nonnull public static <T> T[] resize(T[] array, @Nonnegative int length)
array with the given length.T - the type of the new arrayarray - the array to resizelength - the new length of the arrayNullPointerException - if the type is nullIllegalArgumentException - if the length is lower than array.length@Nonnull public static <T> T[] append(T[] array, @Nullable T element)
element at the last position in the array.T - the component type of the arrayarray - the array to add the element toelement - the object to addNullPointerException - if the array is null@Nonnull public static <T> T[] add(T[] array, @Nonnegative int index, @Nullable T element)
element at the specified position in the array.T - the component type of the arrayarray - the array to add the element toindex - the position of the new objectelement - the object to addNullPointerException - if the array is nullIndexOutOfBoundsException - if the index is out of range (index < 0 || index > array.length)@Nonnull public static <T> T[] addAll(T[] array, int index, Collection<? extends T> elements)
elements at the end of the array.T - the component type of the arrayarray - the array to add the element toelements - the objects to addNullPointerException - if any argument is null@Nonnull public static byte[] addAll(byte[] array1, byte... array2)
array2 at the end of the array1.array1 - the array to add the element toarray2 - the values to addNullPointerException - if any argument is null@Nonnull public static <T> T[] remove(T[] array, @Nonnegative int index)
index from the specified array.T - the component type of the arrayarray - the array to remove the element fromindex - the position of the element to be removedNullPointerException - if the array is nullIndexOutOfBoundsException - if the index is out of range (index < 0 || index > array.length)public static <T> boolean contains(T[] array,
@Nullable
T value)
value is in the given array.array - the array to search throughvalue - the object to findtrue if the array contains the object, false otherwiseNullPointerException - if the array is nullpublic static <T> int indexOf(T[] array,
@Nullable
T value)
value in the array.array - the array to search through for the objectvalue - the value to find, may be null-1 if not foundNullPointerException - if the array is nullpublic static <T> int lastIndexOf(T[] array,
@Nullable
T value)
value in the array.array - the array to traverse for looking for the objectvalue - the object to find, may be null-1 if not foundNullPointerException - if the array is null@Nonnull public static byte[] toPrimitive(Byte... boxedArray)
Byte to an array of primitive types byte.boxedArray - The array of Byte to convert.byte containing the same elements as boxedArray,
in the same order, converted to primitives.public static Byte[] toObject(byte... primitiveArray)
byte to an array of Objects .primitiveArray - The array of to convert.Byte containing the same elements as primitiveArray, in the same order,
converted to boxed types.Copyright © 2017–2019 Atlanmod. All rights reserved.