Package io.micronaut.core.util
Class ArrayUtils
- java.lang.Object
-
- io.micronaut.core.util.ArrayUtils
-
public class ArrayUtils extends java.lang.Object
Utility methods for working with arrays.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static boolean[]
EMPTY_BOOLEAN_ARRAY
An empty boolean array.static byte[]
EMPTY_BYTE_ARRAY
An empty byte array.static char[]
EMPTY_CHAR_ARRAY
An empty char array.static double[]
EMPTY_DOUBLE_ARRAY
An empty double array.static float[]
EMPTY_FLOAT_ARRAY
An empty float array.static int[]
EMPTY_INT_ARRAY
An empty int array.static long[]
EMPTY_LONG_ARRAY
An empty long array.static java.lang.Object[]
EMPTY_OBJECT_ARRAY
An empty object array.static short[]
EMPTY_SHORT_ARRAY
An empty short array.
-
Constructor Summary
Constructors Constructor Description ArrayUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
concat(byte[] a, byte... b)
Concatenate two byte arrays.static <T> T[]
concat(T[] a, T... b)
Concatenate two arrays.static boolean
isEmpty(java.lang.Object[] array)
Whether the given array is empty.static boolean
isNotEmpty(java.lang.Object[] array)
Whether the given array is not empty.static <T> java.util.Iterator<T>
iterator(T... array)
Produce an iterator for the given array.static <T> java.util.Iterator<T>
reverseIterator(T... array)
Produce an iterator for the given array.static <T> T[]
toArray(java.util.Collection<T> collection, java.lang.Class<T> arrayItemClass)
Returns an array containing all of the elements in this collection, using the item class.static <T> T[]
toArray(java.util.Collection<T> collection, java.util.function.IntFunction<T[]> createArrayFn)
Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.static java.lang.Object
toPrimitiveArray(java.lang.Object[] wrapperArray)
Converts a primitive wrapper array to the equivalent primitive array such as Integer[] to int[].static java.lang.String
toString(java.lang.Object[] array)
Produce a string representation of the given array.static java.lang.String
toString(java.lang.String delimiter, java.lang.Object[] array)
Produce a string representation of the given array.static java.lang.Object[]
toWrapperArray(java.lang.Object primitiveArray)
Converts a primitive array to the equivalent wrapper such as int[] to Integer[].
-
-
-
Field Detail
-
EMPTY_OBJECT_ARRAY
public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
An empty object array.
-
EMPTY_BOOLEAN_ARRAY
public static final boolean[] EMPTY_BOOLEAN_ARRAY
An empty boolean array.
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
An empty byte array.
-
EMPTY_CHAR_ARRAY
public static final char[] EMPTY_CHAR_ARRAY
An empty char array.
-
EMPTY_INT_ARRAY
public static final int[] EMPTY_INT_ARRAY
An empty int array.
-
EMPTY_DOUBLE_ARRAY
public static final double[] EMPTY_DOUBLE_ARRAY
An empty double array.
-
EMPTY_LONG_ARRAY
public static final long[] EMPTY_LONG_ARRAY
An empty long array.
-
EMPTY_FLOAT_ARRAY
public static final float[] EMPTY_FLOAT_ARRAY
An empty float array.
-
EMPTY_SHORT_ARRAY
public static final short[] EMPTY_SHORT_ARRAY
An empty short array.
-
-
Method Detail
-
concat
public static <T> T[] concat(T[] a, T... b)
Concatenate two arrays.- Type Parameters:
T
- The array type- Parameters:
a
- The first arrayb
- The second array- Returns:
- The concatenated array
-
concat
public static byte[] concat(byte[] a, byte... b)
Concatenate two byte arrays.- Parameters:
a
- The first arrayb
- The second array- Returns:
- The concatenated array
-
isEmpty
public static boolean isEmpty(java.lang.Object[] array)
Whether the given array is empty.- Parameters:
array
- The array- Returns:
- True if it is
-
isNotEmpty
public static boolean isNotEmpty(java.lang.Object[] array)
Whether the given array is not empty.- Parameters:
array
- The array- Returns:
- True if it is
-
toString
public static java.lang.String toString(@Nullable java.lang.Object[] array)
Produce a string representation of the given array.- Parameters:
array
- The array- Returns:
- The string representation
-
toString
public static java.lang.String toString(java.lang.String delimiter, @Nullable java.lang.Object[] array)
Produce a string representation of the given array.- Parameters:
delimiter
- The delimiterarray
- The array- Returns:
- The string representation
-
iterator
public static <T> java.util.Iterator<T> iterator(T... array)
Produce an iterator for the given array.- Type Parameters:
T
- The array type- Parameters:
array
- The array- Returns:
- The iterator
-
reverseIterator
public static <T> java.util.Iterator<T> reverseIterator(T... array)
Produce an iterator for the given array.- Type Parameters:
T
- The array type- Parameters:
array
- The array- Returns:
- The iterator
-
toArray
public static <T> T[] toArray(java.util.Collection<T> collection, java.util.function.IntFunction<T[]> createArrayFn)
Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.- Type Parameters:
T
- The type of the array- Parameters:
collection
- The collectioncreateArrayFn
- The function to create the array- Returns:
- The array
-
toArray
public static <T> T[] toArray(java.util.Collection<T> collection, java.lang.Class<T> arrayItemClass)
Returns an array containing all of the elements in this collection, using the item class.- Type Parameters:
T
- The type of the array- Parameters:
collection
- The collectionarrayItemClass
- The array item class- Returns:
- The array
- Since:
- 3.0
-
toWrapperArray
public static java.lang.Object[] toWrapperArray(java.lang.Object primitiveArray)
Converts a primitive array to the equivalent wrapper such as int[] to Integer[].- Parameters:
primitiveArray
- The primitive array- Returns:
- The primitive array wrapper.
- Since:
- 3.0.0
-
toPrimitiveArray
public static java.lang.Object toPrimitiveArray(java.lang.Object[] wrapperArray)
Converts a primitive wrapper array to the equivalent primitive array such as Integer[] to int[].- Parameters:
wrapperArray
- The wrapper array- Returns:
- The primitive array.
- Since:
- 3.0.0
-
-