public final class ArrayTools
extends java.lang.Object
| Constructor and Description |
|---|
ArrayTools() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Object[] |
concatArrays(java.lang.Object[]... arrays)
Concatenates an arbitrary number of arrays into a new array, handling null and empty arrays.
|
static java.lang.Object[] |
concatArrays(java.lang.Object[] a1,
java.lang.Object[] a2)
Concatenates two arrays into a new array, handling null values.
|
static java.lang.Object[] |
concatArrays(java.lang.Object[] a1,
java.lang.Object[] a2,
java.lang.Object[] a3)
Concatenates three arrays into a new array, handling null values.
|
static <R,T extends R> |
concatTypedArrays(java.lang.Class<R> componentType,
T[]... arrays)
Concatenates an arbitrary number of arrays into a new typed array,
handling null and empty arrays with optimization checks.
|
static int |
findInsertionIndex(int[] sortedArray,
IntIndexComparator comparator,
int valueToInsert)
Finds the index at which an additional value needs to be inserted into a sorted integer array
to maintain the sorted order according to the given comparator.
|
static int |
findInsertionIndex(int[] sortedArray,
int length,
IntIndexComparator comparator,
int valueToInsert)
Finds the index at which an additional value needs to be inserted into a sorted integer array
to maintain the sorted order according to the given comparator, within a specified effective length.
|
static int |
lastIndexOf(byte[] what,
byte[] within)
Finds the last occurrence of the specified byte array within the given byte array,
searching backward from the end.
|
static int |
lastIndexOf(byte[] what,
byte[] within,
int fromIndex)
Finds the last occurrence of the specified byte array within the given byte array,
searching backward from the specified index.
|
static java.lang.Object[] |
mergeArrays(java.lang.Object[] a1,
java.lang.Object[] a2)
Merges two arrays of objects into a new array with duplicates removed,
preserving the order of the first occurrence of each element.
|
static <R,A extends R,B extends R> |
mergeTypedArrays(java.lang.Class<R> componentType,
A[] a1,
B[] a2)
Merges two typed arrays into a new array with duplicates removed, preserving the order of the first occurrence of each element.
|
static java.lang.Object[] |
removeArrayMemberAtIndex(java.lang.Object[] a,
int i)
Returns a new
Object array without the element at the specified position,
by copying the given Object array into a new Object array without
the element at the specified position. |
static java.lang.Object |
removeTypedArrayMemberAtIndex(java.lang.Object a,
int i)
Similar to
removeArrayMemberAtIndex(java.lang.Object[], int), but with Object parameter and
return type to be casted to the correct array type. |
public static java.lang.Object[] concatArrays(java.lang.Object[] a1,
java.lang.Object[] a2)
This method combines the elements of two arrays (a1 and a2) into a new array.
It is implemented as a convenience wrapper around the varargs method
concatArrays(Object[][]) for two arguments.
a1 - The first array. May be null.a2 - The second array. May be null.public static java.lang.Object[] concatArrays(java.lang.Object[] a1,
java.lang.Object[] a2,
java.lang.Object[] a3)
This method filters all null or empty arrays and then delegates the remaining inputs to the optimized varargs method, avoiding ambiguous varargs calls for single- and zero-array cases.
a1 - The first array. May be null.a2 - The second array. May be null.a3 - The third array. May be null.public static java.lang.Object[] concatArrays(java.lang.Object[]... arrays)
This method combines the elements of all input arrays into a single new array. If zero or one non-null array is provided, no new array is created; the single input array (or an empty array) is returned directly, ensuring optimization. The order of elements is preserved based on the order of the input arrays.
arrays - An arbitrary number of Object arrays. May contain nulls.@SafeVarargs
public static <R,T extends R> R[] concatTypedArrays(java.lang.Class<R> componentType,
T[]... arrays)
R - The type of the elements in the resulting array.T - The common super-type of all input array elements (typically R).componentType - The component type of the resulting array (R).arrays - An arbitrary number of input arrays, whose element types
must be subtypes of R. May contain nulls.public static final java.lang.Object[] mergeArrays(java.lang.Object[] a1,
java.lang.Object[] a2)
a1 - the first arraya2 - the second arraypublic static <R,A extends R,B extends R> R[] mergeTypedArrays(java.lang.Class<R> componentType,
A[] a1,
B[] a2)
This method combines the elements of two arrays (a1 and a2) into a new array, ensuring that only unique elements are included. The order of the elements in the new array is determined by their first occurrence in either of the input arrays. The component type of the arrays is specified by the componentType parameter.
R - The type of the elements in the arrays.A - The type of the first array, which must be a subtype of R.B - The type of the second array, which must be a subtype of R.componentType - The component type of the arrays.a1 - The first array.a2 - The second array.public static final int lastIndexOf(byte[] what,
byte[] within)
what - The byte array to search for.within - The byte array to search within.public static final int lastIndexOf(byte[] what,
byte[] within,
int fromIndex)
what - The byte array to search for.within - The byte array to search within.fromIndex - The index to start the backward search from.public static final java.lang.Object[] removeArrayMemberAtIndex(java.lang.Object[] a,
int i)
Object array without the element at the specified position,
by copying the given Object array into a new Object array without
the element at the specified position. The new Object array will have a length
of a.length - 1, and the original array will be left untouched.a - The Object array to remove the element from.i - The element position to remove.Object array without the element at the specified position.java.lang.IllegalArgumentException - If the given array is null.java.lang.ArrayIndexOutOfBoundsException - If the given element position is out of bounds.public static final java.lang.Object removeTypedArrayMemberAtIndex(java.lang.Object a,
int i)
removeArrayMemberAtIndex(java.lang.Object[], int), but with Object parameter and
return type to be casted to the correct array type.a - The Object array to remove the element from.i - The element position to remove.Object array without the element at the specified position.java.lang.IllegalArgumentException - If the given array is null.java.lang.ArrayIndexOutOfBoundsException - If the given element position is out of bounds.public static final int findInsertionIndex(int[] sortedArray,
IntIndexComparator comparator,
int valueToInsert)
This method performs a binary search to find the first index "i" such that
comparator.compare(valueToInsert, sortedArray[i]) <= 0. If no such element exists
(i.e. valueToInsert is greater than all elements in the array), it returns
the array's length, indicating insertion at the end.
sortedArray - The array, which must be sorted according to the provided comparator.
If null, an IllegalArgumentException is thrown.comparator - The IntIndexComparator used to define the sorting order of the array.
If null, an IllegalArgumentException is thrown.valueToInsert - The integer value to find the insertion index for.java.lang.IllegalArgumentException - if sortedArray or comparator is null.public static final int findInsertionIndex(int[] sortedArray,
int length,
IntIndexComparator comparator,
int valueToInsert)
This method performs a binary search to find the first index "i" such that
comparator.compare(valueToInsert, sortedArray[i]) <= 0. If no such element exists
within the specified "length" (i.e. valueToInsert is greater than all elements
up to "length - 1"), it returns "length", indicating insertion at the end of the effective range.
sortedArray - The array, which must be sorted according to the provided comparator.
If null, an IllegalArgumentException is thrown.length - The effective length of the sorted portion of the array to consider for the binary search.
Must not be larger than the length of the passed "sortedArray".comparator - The IntIndexComparator used to define the sorting order of the array.
If null, an IllegalArgumentException is thrown.valueToInsert - The integer value to find the insertion index for.java.lang.IllegalArgumentException - if sortedArray or comparator is null,
or if "length" is greater than "sortedArray.length".Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.