Package io.micronaut.core.util
Class ArrayUtils
java.lang.Object
io.micronaut.core.util.ArrayUtils
Utility methods for working with arrays.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean[]
An empty boolean array.static final byte[]
An empty byte array.static final char[]
An empty char array.static final double[]
An empty double array.static final float[]
An empty float array.static final int[]
An empty int array.static final long[]
An empty long array.static final Object[]
An empty object array.static final short[]
An empty short array. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
concat
(byte[] a, byte... b) Concatenate two byte arrays.static <T> T[]
concat
(T[] a, T... b) Concatenate two arrays.static boolean
Whether the given array is empty.static boolean
isNotEmpty
(Object[] array) Whether the given array is not empty.static <T> Iterator<T>
iterator
(T... array) Produce an iterator for the given array.static <T> void
reverse
(T[] input) Mutates the passed array by reversing the order of the items in it.static <T> Iterator<T>
reverseIterator
(T... array) Produce an iterator for the given array.static <T> T[]
toArray
(Collection<T> collection, Class<T> arrayItemClass) Returns an array containing all of the elements in this collection, using the item class.static <T> T[]
toArray
(Collection<T> collection, 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 Object
toPrimitiveArray
(Object[] wrapperArray) Converts a primitive wrapper array to the equivalent primitive array such as Integer[] to int[].static String
Produce a string representation of the given array.static String
Produce a string representation of the given array.static Object[]
toWrapperArray
(Object primitiveArray) Converts a primitive array to the equivalent wrapper such as int[] to Integer[].
-
Field Details
-
EMPTY_OBJECT_ARRAY
An empty object array. -
EMPTY_BOOLEAN_ARRAY
public static final boolean[] EMPTY_BOOLEAN_ARRAYAn empty boolean array. -
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAYAn empty byte array. -
EMPTY_CHAR_ARRAY
public static final char[] EMPTY_CHAR_ARRAYAn empty char array. -
EMPTY_INT_ARRAY
public static final int[] EMPTY_INT_ARRAYAn empty int array. -
EMPTY_DOUBLE_ARRAY
public static final double[] EMPTY_DOUBLE_ARRAYAn empty double array. -
EMPTY_LONG_ARRAY
public static final long[] EMPTY_LONG_ARRAYAn empty long array. -
EMPTY_FLOAT_ARRAY
public static final float[] EMPTY_FLOAT_ARRAYAn empty float array. -
EMPTY_SHORT_ARRAY
public static final short[] EMPTY_SHORT_ARRAYAn empty short array.
-
-
Method Details
-
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
Whether the given array is empty.- Parameters:
array
- The array- Returns:
- True if it is
-
isNotEmpty
Whether the given array is not empty.- Parameters:
array
- The array- Returns:
- True if it is
-
toString
Produce a string representation of the given array.- Parameters:
array
- The array- Returns:
- The string representation
-
toString
Produce a string representation of the given array.- Parameters:
delimiter
- The delimiterarray
- The array- Returns:
- The string representation
-
iterator
Produce an iterator for the given array.- Type Parameters:
T
- The array type- Parameters:
array
- The array- Returns:
- The iterator
-
reverseIterator
Produce an iterator for the given array.- Type Parameters:
T
- The array type- Parameters:
array
- The array- Returns:
- The iterator
-
toArray
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
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
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
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
-
reverse
public static <T> void reverse(T[] input) Mutates the passed array by reversing the order of the items in it.- Type Parameters:
T
- The array type- Parameters:
input
- The array- Since:
- 4.0.0
-