Class ArrayUtils

java.lang.Object
io.micronaut.core.util.ArrayUtils

public final class ArrayUtils extends Object
Utility methods for working with arrays.
Since:
1.0
Author:
Graeme Rocher
  • Field Details

    • EMPTY_OBJECT_ARRAY

      public static final 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 Details

    • concat

      public static <T> T[] concat(T[] a, T... b)
      Concatenate two arrays.
      Type Parameters:
      T - The array type
      Parameters:
      a - The first array
      b - The second array
      Returns:
      The concatenated array
    • concat

      public static byte[] concat(byte[] a, byte... b)
      Concatenate two byte arrays.
      Parameters:
      a - The first array
      b - The second array
      Returns:
      The concatenated array
    • isEmpty

      public static boolean isEmpty(Object[] array)
      Whether the given array is empty.
      Parameters:
      array - The array
      Returns:
      True if it is
    • isNotEmpty

      public static boolean isNotEmpty(Object[] array)
      Whether the given array is not empty.
      Parameters:
      array - The array
      Returns:
      True if it is
    • toString

      public static String toString(@Nullable @Nullable Object[] array)
      Produce a string representation of the given array.
      Parameters:
      array - The array
      Returns:
      The string representation
    • toString

      public static String toString(String delimiter, @Nullable @Nullable Object[] array)
      Produce a string representation of the given array.
      Parameters:
      delimiter - The delimiter
      array - The array
      Returns:
      The string representation
    • iterator

      public static <T> 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> 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(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.
      Type Parameters:
      T - The type of the array
      Parameters:
      collection - The collection
      createArrayFn - The function to create the array
      Returns:
      The array
    • toArray

      public 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.
      Type Parameters:
      T - The type of the array
      Parameters:
      collection - The collection
      arrayItemClass - The array item class
      Returns:
      The array
      Since:
      3.0
    • toWrapperArray

      public static Object[] toWrapperArray(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 Object toPrimitiveArray(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
    • 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