java.lang.Object
ushiosan.jvm_utilities.lang.collection.Arrs
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intnumber to represent not found operation in the arrays -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean[]booleanOf(boolean... elements) Generate a primitive boolean arraystatic byte @NotNull []Generate a primitive byte arraystatic char[]charOf(char... elements) Generate a primitive char arraystatic booleanChecks if the array contains the selected element.static booleanChecks if the array contains the selected element.static booleanChecks if the array contains the selected element.static booleanChecks if the array contains the selected element.static booleanChecks if the array contains the selected element.static booleanChecks if the array contains the selected element.static booleanChecks if the array contains the selected element.static booleanChecks if the array contains the selected element.static double[]doubleOf(double... elements) Generate a primitive double arraystatic float[]floatOf(float... elements) Generate a primitive float arraystatic intSearch elements in the arraystatic intSearch elements in the arraystatic intSearch elements in the arraystatic intSearch elements in the arraystatic intSearch elements in the arraystatic intSearch elements in the arraystatic intSearch elements in the arraystatic intSearch elements in the arraystatic int[]intOf(int... elements) Generate a primitive int arraylastElement(byte @NotNull [] array) Returns the last element of the arraylastElement(char @NotNull [] array) Returns the last element of the arraylastElement(double @NotNull [] array) Returns the last element of the arraylastElement(float @NotNull [] array) Returns the last element of the arraylastElement(int @NotNull [] array) Returns the last element of the arraylastElement(long @NotNull [] array) Returns the last element of the arraylastElement(short @NotNull [] array) Returns the last element of the arraylastElement(T @NotNull [] array) Returns the last element of the arraystatic intlastIndexOf(byte @NotNull [] array, byte element) Search an element in the array.static intlastIndexOf(char @NotNull [] array, char element) Search an element in the array.static intlastIndexOf(double @NotNull [] array, double element) Search an element in the array.static intlastIndexOf(float @NotNull [] array, float element) Search an element in the array.static intlastIndexOf(int @NotNull [] array, int element) Search an element in the array.static intlastIndexOf(long @NotNull [] array, long element) Search an element in the array.static intlastIndexOf(short @NotNull [] array, short element) Search an element in the array.static intlastIndexOf(Object @NotNull [] array, @Nullable Object element) Search an element in the array.static long[]longOf(long... elements) Generate a primitive long arrayGenerates a generic array with numeric objects.Generate array from given values.static <T> T[]of(T... elements) Generate array from given values.static short @NotNull []Generate a primitive short arraytoNumberOf(byte[] array) Convert the primitive byte array to a numeric arraytoNumberOf(double[] array) Convert the primitive double array to a numeric arraytoNumberOf(float[] array) Convert the primitive float array to a numeric arraytoNumberOf(int[] array) Convert the primitive int array to a numeric arraytoNumberOf(long[] array) Convert the primitive long array to a numeric arraytoNumberOf(short[] array) Convert the primitive short array to a numeric arraytoObjectArray(Object array) Convert any array to object array.static byteunsafeLastElement(byte @NotNull [] array) Returns the last element of the arraystatic charunsafeLastElement(char @NotNull [] array) Returns the last element of the arraystatic doubleunsafeLastElement(double @NotNull [] array) Returns the last element of the arraystatic floatunsafeLastElement(float @NotNull [] array) Returns the last element of the arraystatic intunsafeLastElement(int @NotNull [] array) Returns the last element of the arraystatic longunsafeLastElement(long @NotNull [] array) Returns the last element of the arraystatic shortunsafeLastElement(short @NotNull [] array) Returns the last element of the arraystatic <T> TunsafeLastElement(T @NotNull [] array) Returns the last element of the array
-
Field Details
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUNDnumber to represent not found operation in the arrays- See Also:
-
-
Method Details
-
of
Generate array from given values. If you want to use primitive arrays, you must use the classes that encapsulate those types. -
of
Generate array from given values. If you want to use primitive arrays, you must use the classes that encapsulate those types. -
indexOf
@Contract(pure=true) public static int indexOf(Object @NotNull [] array, @Nullable @Nullable Object element) Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
lastIndexOf
@Contract(pure=true) public static int lastIndexOf(Object @NotNull [] array, @Nullable @Nullable Object element) Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Type Parameters:
T- generic array type- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Type Parameters:
T- generic array type- Parameters:
array- base array to search- Returns:
- the last element of the array or
nullif array is empty
-
toObjectArray
Convert any array to object array. This also applies to primitive types.Be careful with this method because this method uses a trick to convert primitive types to numeric types and does not use wrapper classes. Instead, the
Numberclass is used for any numeric type (except for the char type).Examples
// For numeric primitives always use Number class Number[] intArr = (Number[]) Arrays.toObjectArray(new int[] {2, 4, 6, 8}); Number[] shortArr = (Number[]) Arrays.toObjectArray(new short[] {12, 21, 42, 120, 0xFF}); Number[] floatArr = (Number[]) Arrays.toObjectArray(new float[] {1f, 2f, 3f, 120.2234f}); // Wrapped clases Boolean[] boolArr = (Boolean[]) Arrays.toObjectArray(new boolean[] {true, false, false, true}); Character[] intArr = (Character[]) Arrays.toObjectArray(new char[] {'H', 'e', 'l', 'l', 'o'});- Parameters:
array- the array to convert- Returns:
- a converted array object
-
numberOf
Generates a generic array with numeric objects.- Parameters:
elements- numeric elements- Returns:
- an array with all numeric elements
-
booleanOf
public static boolean[] booleanOf(boolean... elements) Generate a primitive boolean array- Parameters:
elements- boolean elements- Returns:
- an array with all boolean elements
-
charOf
public static char[] charOf(char... elements) Generate a primitive char array- Parameters:
elements- char elements- Returns:
- an array with all char elements
-
indexOf
Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
lastIndexOf
Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array
- Throws:
IllegalStateException- if the array is empty
-
byteOf
Generate a primitive byte array- Parameters:
elements- byte elements- Returns:
- an array with all bytes
-
toNumberOf
Convert the primitive byte array to a numeric array- Parameters:
array- the array to convert- Returns:
- an array with all numeric objects
- See Also:
-
indexOf
Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
lastIndexOf
Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array
- Throws:
IllegalStateException- if the array is empty
-
shortOf
Generate a primitive short array- Parameters:
elements- short elements- Returns:
- an array with all shot elements
-
toNumberOf
Convert the primitive short array to a numeric array- Parameters:
array- the array to convert- Returns:
- an array with all numeric objects
- See Also:
-
indexOf
Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
lastIndexOf
Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array
- Throws:
IllegalStateException- if the array is empty
-
intOf
public static int[] intOf(int... elements) Generate a primitive int array- Parameters:
elements- int elements- Returns:
- an array with all int elements
-
toNumberOf
Convert the primitive int array to a numeric array- Parameters:
array- the array to convert- Returns:
- an array with all numeric objects
- See Also:
-
indexOf
Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
lastIndexOf
Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array
- Throws:
IllegalStateException- if the array is empty
-
longOf
public static long[] longOf(long... elements) Generate a primitive long array- Parameters:
elements- long elements- Returns:
- an array with all long elements
-
toNumberOf
Convert the primitive long array to a numeric array- Parameters:
array- the array to convert- Returns:
- an array with all numeric objects
- See Also:
-
indexOf
Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
lastIndexOf
Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array
- Throws:
IllegalStateException- if the array is empty
-
floatOf
public static float[] floatOf(float... elements) Generate a primitive float array- Parameters:
elements- float elements- Returns:
- an array with all float elements
-
toNumberOf
Convert the primitive float array to a numeric array- Parameters:
array- the array to convert- Returns:
- an array with all numeric objects
- See Also:
-
indexOf
Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
lastIndexOf
Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array
- Throws:
IllegalStateException- if the array is empty
-
doubleOf
public static double[] doubleOf(double... elements) Generate a primitive double array- Parameters:
elements- double elements- Returns:
- an array with double bytes
-
toNumberOf
Convert the primitive double array to a numeric array- Parameters:
array- the array to convert- Returns:
- an array with all numeric objects
- See Also:
-
indexOf
Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
lastIndexOf
Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Parameters:
array- base array to search- Returns:
- the last element of the array
- Throws:
IllegalStateException- if the array is empty
-