Class ArrayUtils

  • All Implemented Interfaces:
    Utils

    public abstract class ArrayUtils
    extends java.lang.Object
    implements Utils
    The utilities class for Array
    Since:
    1.0.0
    Author:
    Mercy
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean arrayEquals​(boolean[] a, boolean[] b)
      Compares two boolean arrays for equality.
      static boolean arrayEquals​(byte[] a, byte[] b)
      Compares two byte arrays for equality.
      static boolean arrayEquals​(char[] a, char[] b)
      Compares two char arrays for equality.
      static boolean arrayEquals​(double[] a, double[] b)
      Compares two double arrays for equality.
      static boolean arrayEquals​(float[] a, float[] b)
      Compares two float arrays for equality.
      static boolean arrayEquals​(int[] a, int[] b)
      Compares two int arrays for equality.
      static boolean arrayEquals​(long[] a, long[] b)
      Compares two long arrays for equality.
      static boolean arrayEquals​(short[] a, short[] b)
      Compares two short arrays for equality.
      static <T> boolean arrayEquals​(T[] a, T[] b)
      Compares two object arrays for equality.
      static <T> java.lang.String arrayToString​(T[] array)
      Converts the specified array to a string representation.
      static <E> E[] asArray​(java.lang.Iterable<E> elements, java.lang.Class<?> componentType)
      Converts the specified Iterable to an array of the given component type.
      static <E> E[] asArray​(java.util.Collection<E> collection, java.lang.Class<?> componentType)
      Converts the specified Collection to an array of the given component type.
      static <E> E[] asArray​(java.util.Enumeration<E> enumeration, java.lang.Class<?> componentType)
      Converts the specified Enumeration to an array of the given component type.
      static <E> E[] combine​(E[] one, E[]... others)
      Combines the given array with additional arrays into a single new array.
      static <E> E[] combine​(E one, E... others)
      Combines a single element and an array of additional elements into a new array.
      static <E> E[] combineArray​(E[] one, E[]... others)
      Combines the given array with additional arrays into a single new array.
      static boolean contains​(boolean[] values, boolean value)
      Checks if the specified boolean array contains the given value.
      static boolean contains​(byte[] values, byte value)  
      static boolean contains​(char[] values, char value)
      Checks if the specified char array contains the given value using binary search.
      static boolean contains​(double[] values, double value)
      Checks if the specified double array contains the given value using binary search.
      static boolean contains​(float[] values, float value)
      Checks if the specified float array contains the given value using binary search.
      static boolean contains​(int[] values, int value)
      Checks if the specified int array contains the given value using binary search.
      static boolean contains​(long[] values, long value)
      Checks if the specified long array contains the given value using binary search.
      static boolean contains​(short[] values, short value)
      Checks if the specified short array contains the given value using binary search.
      static boolean contains​(java.lang.Object[] values, java.lang.Object value)
      Checks if the specified object array contains the given value.
      static void forEach​(boolean[] values, java.util.function.BiConsumer<java.lang.Integer,​java.lang.Boolean> indexedElementConsumer)
      Iterates over each element of the provided boolean array, applying the given BiConsumer to each element with its index.
      static void forEach​(boolean[] values, java.util.function.Consumer<java.lang.Boolean> consumer)
      Iterates over each element of the provided boolean array, applying the given consumer to each element.
      static void forEach​(byte[] values, java.util.function.BiConsumer<java.lang.Integer,​java.lang.Byte> indexedElementConsumer)
      Iterates over each element of the provided byte array, applying the given BiConsumer to each element with its index.
      static void forEach​(byte[] values, java.util.function.Consumer<java.lang.Byte> consumer)
      Iterates over each element of the provided byte array, applying the given consumer to each element.
      static void forEach​(char[] values, java.util.function.BiConsumer<java.lang.Integer,​java.lang.Character> indexedElementConsumer)
      Iterates over each element of the provided char array, applying the given BiConsumer to each element with its index.
      static void forEach​(char[] values, java.util.function.Consumer<java.lang.Character> consumer)
      Iterates over each element of the provided char array, applying the given consumer to each element.
      static void forEach​(double[] values, java.util.function.BiConsumer<java.lang.Integer,​java.lang.Double> indexedElementConsumer)
      Iterates over each element of the provided double array, applying the given BiConsumer to each element with its index.
      static void forEach​(double[] values, java.util.function.Consumer<java.lang.Double> consumer)
      Iterates over each element of the provided double array, applying the given consumer to each element.
      static void forEach​(float[] values, java.util.function.BiConsumer<java.lang.Integer,​java.lang.Float> indexedElementConsumer)
      Iterates over each element of the provided float array, applying the given BiConsumer to each element with its index.
      static void forEach​(float[] values, java.util.function.Consumer<java.lang.Float> consumer)
      Iterates over each element of the provided float array, applying the given consumer to each element.
      static void forEach​(int[] values, java.util.function.BiConsumer<java.lang.Integer,​java.lang.Integer> indexedElementConsumer)
      Iterates over each element of the provided int array, applying the given BiConsumer to each element with its index.
      static void forEach​(int[] values, java.util.function.Consumer<java.lang.Integer> consumer)
      Iterates over each element of the provided int array, applying the given consumer to each element.
      static void forEach​(long[] values, java.util.function.BiConsumer<java.lang.Integer,​java.lang.Long> indexedElementConsumer)
      Iterates over each element of the provided long array, applying the given BiConsumer to each element with its index.
      static void forEach​(long[] values, java.util.function.Consumer<java.lang.Long> consumer)
      Iterates over each element of the provided long array, applying the given consumer to each element.
      static void forEach​(short[] values, java.util.function.BiConsumer<java.lang.Integer,​java.lang.Short> indexedElementConsumer)
      Iterates over each element of the provided short array, applying the given BiConsumer to each element with its index.
      static void forEach​(short[] values, java.util.function.Consumer<java.lang.Short> consumer)
      Iterates over each element of the provided short array, applying the given consumer to each element.
      static <T> void forEach​(T[] values, java.util.function.BiConsumer<java.lang.Integer,​T> indexedElementConsumer)
      Iterates over each element of the provided array, applying the given BiConsumer to each element with its index.
      static <T> void forEach​(T[] values, java.util.function.Consumer<T> consumer)
      Iterates over each element of the provided array, applying the given consumer to each element.
      static boolean isEmpty​(boolean[] values)
      Checks if the provided boolean array is empty.
      static boolean isEmpty​(byte[] values)
      Checks if the provided byte array is empty.
      static boolean isEmpty​(char[] values)
      Checks if the provided char array is empty.
      static boolean isEmpty​(double[] values)
      Checks if the provided double array is empty.
      static boolean isEmpty​(float[] values)
      Checks if the provided float array is empty.
      static boolean isEmpty​(int[] values)
      Checks if the provided int array is empty.
      static boolean isEmpty​(long[] values)
      Checks if the provided long array is empty.
      static boolean isEmpty​(short[] values)
      Checks if the provided short array is empty.
      static <T> boolean isEmpty​(T[] values)
      Checks if the provided array is empty.
      static boolean isNotEmpty​(boolean[] values)
      Checks if the provided boolean array is not empty.
      static boolean isNotEmpty​(byte[] values)
      Checks if the provided byte array is not empty.
      static boolean isNotEmpty​(char[] values)
      Checks if the provided char array is not empty.
      static boolean isNotEmpty​(double[] values)
      Checks if the provided double array is not empty.
      static boolean isNotEmpty​(float[] values)
      Checks if the provided float array is not empty.
      static boolean isNotEmpty​(int[] values)
      Checks if the provided int array is not empty.
      static boolean isNotEmpty​(long[] values)
      Checks if the provided long array is not empty.
      static boolean isNotEmpty​(short[] values)
      Checks if the provided short array is not empty.
      static <T> boolean isNotEmpty​(T[] values)
      Checks if the provided array is not empty.
      static int length​(boolean[] values)
      Returns the length of the provided array.
      static int length​(byte[] values)
      Returns the length of the provided byte array.
      static int length​(char[] values)
      Returns the length of the provided char array.
      static int length​(double[] values)
      Returns the length of the provided double array.
      static int length​(float[] values)
      Returns the length of the provided float array.
      static int length​(int[] values)
      Returns the length of the provided int array.
      static int length​(long[] values)
      Returns the length of the provided long array.
      static int length​(short[] values)
      Returns the length of the provided short array.
      static <T> int length​(T[] values)
      Returns the length of the provided array.
      static <E> E[] newArray​(java.lang.Class<?> componentType, int length)
      Creates a new array with the specified component type and length.
      static <T> T[] of​(T... values)
      Creates an array from the provided elements.
      static <T> T[] ofArray​(T... values)
      Creates an array from the provided elements.
      static boolean[] ofBooleans​(boolean... values)
      Creates a new boolean array from the provided elements.
      static byte[] ofBytes​(byte... values)
      Creates a new byte array from the provided elements.
      static char[] ofChars​(char... values)
      Creates a new char array from the provided elements.
      static double[] ofDoubles​(double... values)
      Creates a new double array from the provided elements.
      static float[] ofFloats​(float... values)
      Creates a new float array from the provided elements.
      static int[] ofInts​(int... values)
      Creates a new int array from the provided elements.
      static long[] ofLongs​(long... values)
      Creates a new long array from the provided elements.
      static short[] ofShorts​(short... values)
      Creates a new short array from the provided elements.
      static <T> T[] reverse​(T[] a)
      Reverses the elements of the specified array in-place.
      static <T> int size​(T[] values)
      Returns the length of the provided array.
      static <T> T[] toArrayReversed​(java.util.Collection<?> coll, T[] array)
      Dump the contents of the given collection into the given array, in reverse order.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_BOOLEAN_ARRAY

        public static final boolean[] EMPTY_BOOLEAN_ARRAY
        An empty immutable boolean array.
      • EMPTY_CHAR_ARRAY

        public static final char[] EMPTY_CHAR_ARRAY
        An empty immutable char array.
      • EMPTY_BYTE_ARRAY

        public static final byte[] EMPTY_BYTE_ARRAY
        An empty immutable byte array.
      • EMPTY_SHORT_ARRAY

        public static final short[] EMPTY_SHORT_ARRAY
        An empty immutable short array.
      • EMPTY_INT_ARRAY

        public static final int[] EMPTY_INT_ARRAY
        An empty immutable int array.
      • EMPTY_LONG_ARRAY

        public static final long[] EMPTY_LONG_ARRAY
        An empty immutable long array.
      • EMPTY_FLOAT_ARRAY

        public static final float[] EMPTY_FLOAT_ARRAY
        An empty immutable float array.
      • EMPTY_DOUBLE_ARRAY

        public static final double[] EMPTY_DOUBLE_ARRAY
        An empty immutable double array.
      • EMPTY_OBJECT_ARRAY

        public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
        An empty immutable Object array.
      • EMPTY_BOOLEAN_OBJECT_ARRAY

        public static final java.lang.Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY
        An empty immutable Boolean array.
      • EMPTY_BYTE_OBJECT_ARRAY

        public static final java.lang.Byte[] EMPTY_BYTE_OBJECT_ARRAY
        An empty immutable Byte array.
      • EMPTY_CHARACTER_OBJECT_ARRAY

        public static final java.lang.Character[] EMPTY_CHARACTER_OBJECT_ARRAY
        An empty immutable Character array.
      • EMPTY_SHORT_OBJECT_ARRAY

        public static final java.lang.Short[] EMPTY_SHORT_OBJECT_ARRAY
        An empty immutable Short array.
      • EMPTY_INTEGER_OBJECT_ARRAY

        public static final java.lang.Integer[] EMPTY_INTEGER_OBJECT_ARRAY
        An empty immutable Integer array.
      • EMPTY_LONG_OBJECT_ARRAY

        public static final java.lang.Long[] EMPTY_LONG_OBJECT_ARRAY
        An empty immutable Long array.
      • EMPTY_FLOAT_OBJECT_ARRAY

        public static final java.lang.Float[] EMPTY_FLOAT_OBJECT_ARRAY
        An empty immutable Float array.
      • EMPTY_DOUBLE_OBJECT_ARRAY

        public static final java.lang.Double[] EMPTY_DOUBLE_OBJECT_ARRAY
        An empty immutable Double array.
      • EMPTY_CLASS_ARRAY

        public static final java.lang.Class<?>[] EMPTY_CLASS_ARRAY
        An empty immutable Class array.
      • EMPTY_STRING_ARRAY

        public static final java.lang.String[] EMPTY_STRING_ARRAY
        An empty immutable String array.
      • EMPTY_FILE_ARRAY

        public static final java.io.File[] EMPTY_FILE_ARRAY
        An empty immutable File array.
      • EMPTY_URL_ARRAY

        public static final java.net.URL[] EMPTY_URL_ARRAY
        An empty immutable URL array.
      • EMPTY_PARAMETER_ARRAY

        public static final java.lang.reflect.Parameter[] EMPTY_PARAMETER_ARRAY
        An empty immutable Parameter array.
      • EMPTY_TYPE_ARRAY

        public static final java.lang.reflect.Type[] EMPTY_TYPE_ARRAY
        An empty immutable Type array
      • EMPTY_ANNOTATION_ARRAY

        public static final java.lang.annotation.Annotation[] EMPTY_ANNOTATION_ARRAY
        An empty immutable Annotation array
    • Method Detail

      • of

        public static <T> T[] of​(T... values)
        Creates an array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is inferred from the type of the first element passed, or from the context if the method is used in a typed assignment.

        Example Usage

        
         String[] strings = ArrayUtils.of("one", "two", "three");
         Integer[] integers = ArrayUtils.of(1, 2, 3);
         
        Type Parameters:
        T - the class of the objects in the array
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        an array containing the specified elements
      • ofBooleans

        public static boolean[] ofBooleans​(boolean... values)
        Creates a new boolean array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.

        Example Usage

        
         boolean[] booleans = ArrayUtils.ofBooleans(true, false, true);
         
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        a newly created array containing the specified elements
      • ofBytes

        public static byte[] ofBytes​(byte... values)
        Creates a new byte array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.

        Example Usage

        
         byte[] bytes = ArrayUtils.ofBytes((byte) 1, (byte) 2, (byte) 3);
         
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        a newly created array containing the specified elements
      • ofChars

        public static char[] ofChars​(char... values)
        Creates a new char array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.

        Example Usage

        
         char[] chars = ArrayUtils.ofChars('a', 'b', 'c');
         
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        a newly created array containing the specified elements
      • ofShorts

        public static short[] ofShorts​(short... values)
        Creates a new short array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.

        Example Usage

        
         short[] shorts = ArrayUtils.ofShorts((short) 1, (short) 2, (short) 3);
         
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        a newly created array containing the specified elements
      • ofInts

        public static int[] ofInts​(int... values)
        Creates a new int array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.

        Example Usage

        
         int[] ints = ArrayUtils.ofInts(1, 2, 3);
         
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        a newly created array containing the specified elements
      • ofLongs

        public static long[] ofLongs​(long... values)
        Creates a new long array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.

        Example Usage

        
         long[] longs = ArrayUtils.ofLongs(1L, 2L, 3L);
         
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        a newly created array containing the specified elements
      • ofFloats

        public static float[] ofFloats​(float... values)
        Creates a new float array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.

        Example Usage

        
         float[] floats = ArrayUtils.ofFloats(1.0f, 2.0f, 3.0f);
         
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        a newly created array containing the specified elements
      • ofDoubles

        public static double[] ofDoubles​(double... values)
        Creates a new double array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is explicitly defined by the method's return type.

        Example Usage

        
         double[] doubles = ArrayUtils.ofDoubles(1.0, 2.0, 3.0);
         
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        a newly created array containing the specified elements
      • ofArray

        public static <T> T[] ofArray​(T... values)
        Creates an array from the provided elements.

        This method returns an array containing the specified elements. The type of the returned array is inferred from the type of the first element passed, or from the context if the method is used in a typed assignment.

        Example Usage

        
         String[] strings = ArrayUtils.ofArray("one", "two", "three");
         Integer[] integers = ArrayUtils.ofArray(1, 2, 3);
         
        Type Parameters:
        T - the class of the objects in the array
        Parameters:
        values - the elements to be included in the resulting array
        Returns:
        an array containing the specified elements
      • length

        public static int length​(boolean[] values)
        Returns the length of the provided array.

        If the array is null, this method returns 0.

        Example Usage

        
         int length = ArrayUtils.length(new boolean[] { true, false }); // returns 2
         int nullArrayLength = ArrayUtils.length((boolean[]) null); // returns 0
         
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • length

        public static int length​(byte[] values)
        Returns the length of the provided byte array.

        If the array is null, this method returns 0.

        Example Usage

        
         int length = ArrayUtils.length(new byte[] { 1, 2 }); // returns 2
         int nullArrayLength = ArrayUtils.length((byte[]) null); // returns 0
         
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • length

        public static int length​(char[] values)
        Returns the length of the provided char array.

        If the array is null, this method returns 0.

        Example Usage

        
         int length = ArrayUtils.length(new char[] { 'a', 'b' }); // returns 2
         int nullArrayLength = ArrayUtils.length((char[]) null); // returns 0
         
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • length

        public static int length​(short[] values)
        Returns the length of the provided short array.

        If the array is null, this method returns 0.

        Example Usage

        
         int length = ArrayUtils.length(new short[] { 1, 2 }); // returns 2
         int nullArrayLength = ArrayUtils.length((short[]) null); // returns 0
         
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • length

        public static int length​(int[] values)
        Returns the length of the provided int array.

        If the array is null, this method returns 0.

        Example Usage

        
         int length = ArrayUtils.length(new int[] { 1, 2, 3 }); // returns 3
         int nullArrayLength = ArrayUtils.length((int[]) null); // returns 0
         
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • length

        public static int length​(long[] values)
        Returns the length of the provided long array.

        If the array is null, this method returns 0.

        Example Usage

        
         int length = ArrayUtils.length(new long[] { 1L, 2L }); // returns 2
         int nullArrayLength = ArrayUtils.length((long[]) null); // returns 0
         
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • length

        public static int length​(float[] values)
        Returns the length of the provided float array.

        If the array is null, this method returns 0.

        Example Usage

        
         int length = ArrayUtils.length(new float[] { 1.0f, 2.0f }); // returns 2
         int nullArrayLength = ArrayUtils.length((float[]) null); // returns 0
         
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • length

        public static int length​(double[] values)
        Returns the length of the provided double array.

        If the array is null, this method returns 0.

        Example Usage

        
         int length = ArrayUtils.length(new double[] { 1.0, 2.0 }); // returns 2
         int nullArrayLength = ArrayUtils.length((double[]) null); // returns 0
         
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • length

        public static <T> int length​(T[] values)
        Returns the length of the provided array.

        If the array is null, this method returns 0.

        Example Usage

        
         Integer[] integers = {1, 2, 3};
         int length = ArrayUtils.length(integers); // returns 3
        
         String[] strings = null;
         int nullArrayLength = ArrayUtils.length(strings); // returns 0
         
        Type Parameters:
        T - the class of the objects in the array
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • size

        public static <T> int size​(T[] values)
        Returns the length of the provided array.

        If the array is null, this method returns 0.

        Example Usage

        
         Integer[] integers = {1, 2, 3};
         int size = ArrayUtils.size(integers); // returns 3
        
         String[] strings = null;
         int nullArraySize = ArrayUtils.size(strings); // returns 0
         
        Type Parameters:
        T - the class of the objects in the array
        Parameters:
        values - the array to determine the length of
        Returns:
        the length of the array, or 0 if the array is null
      • isEmpty

        public static boolean isEmpty​(boolean[] values)
        Checks if the provided boolean array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         boolean[] emptyArray = {};
         boolean result1 = ArrayUtils.isEmpty(emptyArray); // returns true
        
         boolean[] nonEmptyArray = {true, false};
         boolean result2 = ArrayUtils.isEmpty(nonEmptyArray); // returns false
        
         boolean result3 = ArrayUtils.isEmpty((boolean[]) null); // returns true
         
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isEmpty

        public static boolean isEmpty​(byte[] values)
        Checks if the provided byte array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         byte[] emptyArray = {};
         boolean result1 = ArrayUtils.isEmpty(emptyArray); // returns true
        
         byte[] nonEmptyArray = {1, 2};
         boolean result2 = ArrayUtils.isEmpty(nonEmptyArray); // returns false
        
         boolean result3 = ArrayUtils.isEmpty((byte[]) null); // returns true
         
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isEmpty

        public static boolean isEmpty​(char[] values)
        Checks if the provided char array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         char[] emptyArray = {};
         boolean result1 = ArrayUtils.isEmpty(emptyArray); // returns true
        
         char[] nonEmptyArray = {'a', 'b'};
         boolean result2 = ArrayUtils.isEmpty(nonEmptyArray); // returns false
        
         boolean result3 = ArrayUtils.isEmpty((char[]) null); // returns true
         
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isEmpty

        public static boolean isEmpty​(short[] values)
        Checks if the provided short array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         short[] emptyArray = {};
         boolean result1 = ArrayUtils.isEmpty(emptyArray); // returns true
        
         short[] nonEmptyArray = {1, 2};
         boolean result2 = ArrayUtils.isEmpty(nonEmptyArray); // returns false
        
         boolean result3 = ArrayUtils.isEmpty((short[]) null); // returns true
         
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isEmpty

        public static boolean isEmpty​(int[] values)
        Checks if the provided int array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         int[] emptyArray = {};
         boolean result1 = ArrayUtils.isEmpty(emptyArray); // returns true
        
         int[] nonEmptyArray = {1, 2};
         boolean result2 = ArrayUtils.isEmpty(nonEmptyArray); // returns false
        
         boolean result3 = ArrayUtils.isEmpty((int[]) null); // returns true
         
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isEmpty

        public static boolean isEmpty​(long[] values)
        Checks if the provided long array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         long[] emptyArray = {};
         boolean result1 = ArrayUtils.isEmpty(emptyArray); // returns true
        
         long[] nonEmptyArray = {1L, 2L};
         boolean result2 = ArrayUtils.isEmpty(nonEmptyArray); // returns false
        
         boolean result3 = ArrayUtils.isEmpty((long[]) null); // returns true
         
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isEmpty

        public static boolean isEmpty​(float[] values)
        Checks if the provided float array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         float[] emptyArray = {};
         boolean result1 = ArrayUtils.isEmpty(emptyArray); // returns true
        
         float[] nonEmptyArray = {1.0f, 2.0f};
         boolean result2 = ArrayUtils.isEmpty(nonEmptyArray); // returns false
        
         boolean result3 = ArrayUtils.isEmpty((float[]) null); // returns true
         
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isEmpty

        public static boolean isEmpty​(double[] values)
        Checks if the provided double array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         double[] emptyArray = {};
         boolean result1 = ArrayUtils.isEmpty(emptyArray); // returns true
        
         double[] nonEmptyArray = {1.0, 2.0};
         boolean result2 = ArrayUtils.isEmpty(nonEmptyArray); // returns false
        
         boolean result3 = ArrayUtils.isEmpty((double[]) null); // returns true
         
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isEmpty

        public static <T> boolean isEmpty​(T[] values)
        Checks if the provided array is empty.

        This method returns true if the specified array has zero elements or is null. It provides a convenient way to check for emptiness without explicitly handling null cases.

        Example Usage

        
         Integer[] integers = {};
         boolean result1 = ArrayUtils.isEmpty(integers); // returns true
        
         String[] strings = {"one", "two"};
         boolean result2 = ArrayUtils.isEmpty(strings); // returns false
        
         Object[] objects = null;
         boolean result3 = ArrayUtils.isEmpty(objects); // returns true
         
        Type Parameters:
        T - the class of the objects in the array
        Parameters:
        values - the array to check for emptiness
        Returns:
        true if the array is null or has no elements, otherwise false
      • isNotEmpty

        public static boolean isNotEmpty​(boolean[] values)
        Checks if the provided boolean array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         boolean[] emptyArray = {};
         boolean result1 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         boolean[] nonEmptyArray = {true, false};
         boolean result2 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         boolean result3 = ArrayUtils.isNotEmpty((boolean[]) null); // returns false
         
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • isNotEmpty

        public static boolean isNotEmpty​(byte[] values)
        Checks if the provided byte array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         byte[] emptyArray = {};
         boolean result1 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         byte[] nonEmptyArray = {1, 2};
         boolean result2 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         boolean result3 = ArrayUtils.isNotEmpty((byte[]) null); // returns false
         
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • isNotEmpty

        public static boolean isNotEmpty​(char[] values)
        Checks if the provided char array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         char[] emptyArray = {};
         boolean result1 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         char[] nonEmptyArray = {'a', 'b'};
         boolean result2 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         boolean result3 = ArrayUtils.isNotEmpty((char[]) null); // returns false
         
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • isNotEmpty

        public static boolean isNotEmpty​(short[] values)
        Checks if the provided short array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         short[] emptyArray = {};
         boolean result1 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         short[] nonEmptyArray = {1, 2};
         boolean result2 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         boolean result3 = ArrayUtils.isNotEmpty((short[]) null); // returns false
         
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • isNotEmpty

        public static boolean isNotEmpty​(int[] values)
        Checks if the provided int array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         int[] emptyArray = {};
         boolean result1 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         int[] nonEmptyArray = {1, 2};
         boolean result2 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         boolean result3 = ArrayUtils.isNotEmpty((int[]) null); // returns false
         
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • isNotEmpty

        public static boolean isNotEmpty​(long[] values)
        Checks if the provided long array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         long[] emptyArray = {};
         boolean result1 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         long[] nonEmptyArray = {1L, 2L};
         boolean result2 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         boolean result3 = ArrayUtils.isNotEmpty((long[]) null); // returns false
         
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • isNotEmpty

        public static boolean isNotEmpty​(float[] values)
        Checks if the provided float array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         float[] emptyArray = {};
         boolean result1 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         float[] nonEmptyArray = {1.0f, 2.0f};
         boolean result2 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         boolean result3 = ArrayUtils.isNotEmpty((float[]) null); // returns false
         
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • isNotEmpty

        public static boolean isNotEmpty​(double[] values)
        Checks if the provided double array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         double[] emptyArray = {};
         boolean result1 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         double[] nonEmptyArray = {1.0, 2.0};
         boolean result2 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         boolean result3 = ArrayUtils.isNotEmpty((double[]) null); // returns false
         
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • isNotEmpty

        public static <T> boolean isNotEmpty​(T[] values)
        Checks if the provided array is not empty.

        This method returns true if the specified array has at least one element. It provides a convenient way to check for non-emptiness without explicitly handling null cases.

        Example Usage

        
         Integer[] nonEmptyArray = {1, 2, 3};
         boolean result1 = ArrayUtils.isNotEmpty(nonEmptyArray); // returns true
        
         String[] emptyArray = {};
         boolean result2 = ArrayUtils.isNotEmpty(emptyArray); // returns false
        
         Object[] nullArray = null;
         boolean result3 = ArrayUtils.isNotEmpty(nullArray); // returns false
         
        Type Parameters:
        T - the class of the objects in the array
        Parameters:
        values - the array to check for non-emptiness
        Returns:
        true if the array has at least one element, otherwise false
      • arrayEquals

        public static boolean arrayEquals​(boolean[] a,
                                          boolean[] b)
        Compares two boolean arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal.

        Example Usage

        
         boolean[] array1 = {true, false, true};
         boolean[] array2 = {true, false, true};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         boolean[] array3 = {true, false, false};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         boolean result3 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result4 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • arrayEquals

        public static boolean arrayEquals​(byte[] a,
                                          byte[] b)
        Compares two byte arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal.

        Example Usage

        
         byte[] array1 = {1, 2, 3};
         byte[] array2 = {1, 2, 3};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         byte[] array3 = {1, 2, 4};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         boolean result3 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result4 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • arrayEquals

        public static boolean arrayEquals​(char[] a,
                                          char[] b)
        Compares two char arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal.

        Example Usage

        
         char[] array1 = {'a', 'b', 'c'};
         char[] array2 = {'a', 'b', 'c'};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         char[] array3 = {'a', 'b', 'd'};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         boolean result3 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result4 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • arrayEquals

        public static boolean arrayEquals​(short[] a,
                                          short[] b)
        Compares two short arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal.

        Example Usage

        
         short[] array1 = {1, 2, 3};
         short[] array2 = {1, 2, 3};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         short[] array3 = {1, 2, 4};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         boolean result3 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result4 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • arrayEquals

        public static boolean arrayEquals​(int[] a,
                                          int[] b)
        Compares two int arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal.

        Example Usage

        
         int[] array1 = {1, 2, 3};
         int[] array2 = {1, 2, 3};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         int[] array3 = {1, 2, 4};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         boolean result3 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result4 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • arrayEquals

        public static boolean arrayEquals​(long[] a,
                                          long[] b)
        Compares two long arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal.

        Example Usage

        
         long[] array1 = {1L, 2L, 3L};
         long[] array2 = {1L, 2L, 3L};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         long[] array3 = {1L, 2L, 4L};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         boolean result3 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result4 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • arrayEquals

        public static boolean arrayEquals​(float[] a,
                                          float[] b)
        Compares two float arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal.

        Example Usage

        
         float[] array1 = {1.0f, 2.0f, 3.0f};
         float[] array2 = {1.0f, 2.0f, 3.0f};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         float[] array3 = {1.0f, 2.0f, 4.0f};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         boolean result3 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result4 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • arrayEquals

        public static boolean arrayEquals​(double[] a,
                                          double[] b)
        Compares two double arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal.

        Example Usage

        
         double[] array1 = {1.0, 2.0, 3.0};
         double[] array2 = {1.0, 2.0, 3.0};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         double[] array3 = {1.0, 2.0, 4.0};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         boolean result3 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result4 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • arrayEquals

        public static <T> boolean arrayEquals​(T[] a,
                                              T[] b)
        Compares two object arrays for equality.

        This method checks if the two provided arrays are equal by comparing each element. The arrays are considered equal if they have the same length and all corresponding elements are equal according to their own equals methods.

        Example Usage

        
         String[] array1 = {"one", "two", "three"};
         String[] array2 = {"one", "two", "three"};
         boolean result1 = ArrayUtils.arrayEquals(array1, array2); // returns true
        
         String[] array3 = {"one", "two", "four"};
         boolean result2 = ArrayUtils.arrayEquals(array1, array3); // returns false
        
         Integer[] array4 = {1, 2, 3};
         Integer[] array5 = {1, 2, 3};
         boolean result3 = ArrayUtils.arrayEquals(array4, array5); // returns true
        
         boolean result4 = ArrayUtils.arrayEquals(null, null); // returns true
         boolean result5 = ArrayUtils.arrayEquals(array1, null); // returns false
         
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        true if both arrays are equal; otherwise, false
      • asArray

        public static <E> E[] asArray​(java.util.Enumeration<E> enumeration,
                                      java.lang.Class<?> componentType)
        Converts the specified Enumeration to an array of the given component type.

        This method uses the provided Enumeration and converts it into an array. The type of the returned array is determined by the specified component type.

        Example Usage

        
         Vector<String> vector = new Vector<>(Arrays.asList("one", "two", "three"));
         String[] array = ArrayUtils.asArray(vector.elements(), String.class);
         
        Type Parameters:
        E - the type of elements in the enumeration
        Parameters:
        enumeration - the enumeration to convert
        componentType - the type of the array components
        Returns:
        an array containing all elements from the enumeration
      • asArray

        public static <E> E[] asArray​(java.lang.Iterable<E> elements,
                                      java.lang.Class<?> componentType)
        Converts the specified Iterable to an array of the given component type.

        This method uses the provided Iterable and converts it into an array. The type of the returned array is determined by the specified component type. Internally, it delegates to asArray(Collection, Class) after converting the iterable to a collection.

        Example Usage

        
         List<String> list = Arrays.asList("one", "two", "three");
         String[] array = ArrayUtils.asArray(list, String.class);
         
        Type Parameters:
        E - the type of elements in the iterable
        Parameters:
        elements - the iterable containing elements to convert
        componentType - the type of the array components
        Returns:
        an array containing all elements from the iterable
      • asArray

        public static <E> E[] asArray​(java.util.Collection<E> collection,
                                      java.lang.Class<?> componentType)
        Converts the specified Collection to an array of the given component type.

        This method uses the provided Collection and converts it into an array. The type of the returned array is determined by the specified component type. Internally, it uses reflection to create a new array instance of the desired type and populates it with elements from the collection.

        Example Usage

        
         List<String> list = Arrays.asList("one", "two", "three");
         String[] array = ArrayUtils.asArray(list, String.class);
         
        Type Parameters:
        E - the type of elements in the collection
        Parameters:
        collection - the collection containing elements to convert
        componentType - the type of the array components
        Returns:
        an array containing all elements from the collection
      • newArray

        public static <E> E[] newArray​(java.lang.Class<?> componentType,
                                       int length)
        Creates a new array with the specified component type and length.

        This method uses reflection to create a new array instance of the specified component type and length. It provides a flexible way to instantiate arrays dynamically at runtime.

        Example Usage

        
         String[] stringArray = ArrayUtils.newArray(String.class, 3);
         Integer[] integerArray = ArrayUtils.newArray(Integer.class, 5);
         
        Type Parameters:
        E - the type of the array elements
        Parameters:
        componentType - the type of the array components
        length - the length of the array to be created
        Returns:
        a newly created array of the specified component type and length
      • combine

        public static <E> E[] combine​(E one,
                                      E... others)
        Combines a single element and an array of additional elements into a new array.

        This method creates a new array by combining the provided single element with the elements from the 'others' array. If the 'one' element is not an array, it will be placed as the first element in the resulting array followed by the elements from 'others'. If the 'one' element is an array, this method delegates to combineArray(Object[], Object[]...).

        Example Usage

        
         String single = "first";
         String[] others = {"second", "third"};
         String[] result = ArrayUtils.combine(single, others);
         // result contains ["first", "second", "third"]
        
         Integer[] arrayOne = {1, 2};
         Integer[] othersArray = {3, 4};
         Integer[] resultArray = ArrayUtils.combine(arrayOne, othersArray);
         // resultArray contains [1, 2, 3, 4]
         
        Parameters:
        one - the single element to combine. If it's an array, it will be combined with the elements from 'others'.
        others - the array of additional elements to combine
        Returns:
        a new array containing the combined elements
      • combine

        public static <E> E[] combine​(E[] one,
                                      E[]... others)
        Combines the given array with additional arrays into a single new array.

        This method takes an initial array and a variable number of additional arrays, combining all into a single new array. It is useful for merging multiple arrays efficiently while maintaining type safety.

        Example Usage

        
         String[] array1 = {"one", "two"};
         String[] array2 = {"three", "four"};
         String[] combined = ArrayUtils.combine(array1, array2);
         // combined contains ["one", "two", "three", "four"]
        
         Integer[] arrayA = {1, 2};
         Integer[] arrayB = {3, 4};
         Integer[] arrayC = {5, 6};
         Integer[] combinedArrays = ArrayUtils.combine(arrayA, arrayB, arrayC);
         // combinedArrays contains [1, 2, 3, 4, 5, 6]
         
        Type Parameters:
        E - the type of elements in the arrays
        Parameters:
        one - the initial array to combine
        others - a variable number of additional arrays to merge with the initial array
        Returns:
        a new array containing all elements from the provided arrays
      • combineArray

        public static <E> E[] combineArray​(E[] one,
                                           E[]... others)
        Combines the given array with additional arrays into a single new array.

        This method takes an initial array and a variable number of additional arrays, combining all into a single new array. It is useful for merging multiple arrays efficiently while maintaining type safety.

        Example Usage

        
         String[] array1 = {"one", "two"};
         String[] array2 = {"three", "four"};
         String[] combined = ArrayUtils.combineArray(array1, array2);
         // combined contains ["one", "two", "three", "four"]
        
         Integer[] arrayA = {1, 2};
         Integer[] arrayB = {3, 4};
         Integer[] arrayC = {5, 6};
         Integer[] combinedArrays = ArrayUtils.combineArray(arrayA, arrayB, arrayC);
         // combinedArrays contains [1, 2, 3, 4, 5, 6]
         
        Type Parameters:
        E - the type of elements in the arrays
        Parameters:
        one - the initial array to combine
        others - a variable number of additional arrays to merge with the initial array
        Returns:
        a new array containing all elements from the provided arrays
      • forEach

        public static void forEach​(boolean[] values,
                                   java.util.function.Consumer<java.lang.Boolean> consumer)
        Iterates over each element of the provided boolean array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over primitive arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         boolean[] booleans = {true, false, true};
         ArrayUtils.forEach(booleans, value -> System.out.println("Value: " + value));
         
        Parameters:
        values - the boolean array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static void forEach​(byte[] values,
                                   java.util.function.Consumer<java.lang.Byte> consumer)
        Iterates over each element of the provided byte array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over primitive arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         byte[] bytes = {(byte) 1, (byte) 2, (byte) 3};
         ArrayUtils.forEach(bytes, value -> System.out.println("Value: " + value));
         
        Parameters:
        values - the byte array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static void forEach​(char[] values,
                                   java.util.function.Consumer<java.lang.Character> consumer)
        Iterates over each element of the provided char array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over primitive arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         char[] chars = {'a', 'b', 'c'};
         ArrayUtils.forEach(chars, value -> System.out.println("Value: " + value));
         
        Parameters:
        values - the char array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static void forEach​(short[] values,
                                   java.util.function.Consumer<java.lang.Short> consumer)
        Iterates over each element of the provided short array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over primitive arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         short[] shorts = {(short) 1, (short) 2, (short) 3};
         ArrayUtils.forEach(shorts, value -> System.out.println("Value: " + value));
         
        Parameters:
        values - the short array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static void forEach​(int[] values,
                                   java.util.function.Consumer<java.lang.Integer> consumer)
        Iterates over each element of the provided int array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over primitive arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         int[] ints = {1, 2, 3};
         ArrayUtils.forEach(ints, value -> System.out.println("Value: " + value));
         
        Parameters:
        values - the int array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static void forEach​(long[] values,
                                   java.util.function.Consumer<java.lang.Long> consumer)
        Iterates over each element of the provided long array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over primitive arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         long[] longs = {1L, 2L, 3L};
         ArrayUtils.forEach(longs, value -> System.out.println("Value: " + value));
         
        Parameters:
        values - the long array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static void forEach​(float[] values,
                                   java.util.function.Consumer<java.lang.Float> consumer)
        Iterates over each element of the provided float array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over primitive arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         float[] floats = {1.0f, 2.0f, 3.0f};
         ArrayUtils.forEach(floats, value -> System.out.println("Value: " + value));
         
        Parameters:
        values - the float array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static void forEach​(double[] values,
                                   java.util.function.Consumer<java.lang.Double> consumer)
        Iterates over each element of the provided double array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over primitive arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         double[] doubles = {1.0, 2.0, 3.0};
         ArrayUtils.forEach(doubles, value -> System.out.println("Value: " + value));
         
        Parameters:
        values - the double array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static <T> void forEach​(T[] values,
                                       java.util.function.Consumer<T> consumer)
        Iterates over each element of the provided array, applying the given consumer to each element.

        This method is a convenience utility that allows for functional-style iteration over arrays. The consumer receives each element in turn; if the array is null or empty, no action is performed.

        Example Usage

        
         String[] strings = {"one", "two", "three"};
         ArrayUtils.forEach(strings, value -> System.out.println("Value: " + value));
         
        Type Parameters:
        T - the type of elements in the array
        Parameters:
        values - the array to iterate over
        consumer - the operation to perform on each element
      • forEach

        public static void forEach​(boolean[] values,
                                   java.util.function.BiConsumer<java.lang.Integer,​java.lang.Boolean> indexedElementConsumer)
        Iterates over each element of the provided boolean array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over a primitive boolean array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         boolean[] booleans = {true, false, true};
         ArrayUtils.forEach(booleans, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Parameters:
        values - the boolean array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • forEach

        public static void forEach​(byte[] values,
                                   java.util.function.BiConsumer<java.lang.Integer,​java.lang.Byte> indexedElementConsumer)
        Iterates over each element of the provided byte array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over a primitive byte array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         byte[] bytes = {(byte) 1, (byte) 2, (byte) 3};
         ArrayUtils.forEach(bytes, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Parameters:
        values - the byte array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • forEach

        public static void forEach​(char[] values,
                                   java.util.function.BiConsumer<java.lang.Integer,​java.lang.Character> indexedElementConsumer)
        Iterates over each element of the provided char array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over a primitive char array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         char[] chars = {'a', 'b', 'c'};
         ArrayUtils.forEach(chars, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Parameters:
        values - the char array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • forEach

        public static void forEach​(short[] values,
                                   java.util.function.BiConsumer<java.lang.Integer,​java.lang.Short> indexedElementConsumer)
        Iterates over each element of the provided short array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over a primitive short array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         short[] shorts = {(short) 1, (short) 2, (short) 3};
         ArrayUtils.forEach(shorts, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Parameters:
        values - the short array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • forEach

        public static void forEach​(int[] values,
                                   java.util.function.BiConsumer<java.lang.Integer,​java.lang.Integer> indexedElementConsumer)
        Iterates over each element of the provided int array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over a primitive int array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         int[] ints = {1, 2, 3};
         ArrayUtils.forEach(ints, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Parameters:
        values - the int array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • forEach

        public static void forEach​(long[] values,
                                   java.util.function.BiConsumer<java.lang.Integer,​java.lang.Long> indexedElementConsumer)
        Iterates over each element of the provided long array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over a primitive long array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         long[] longs = {1L, 2L, 3L};
         ArrayUtils.forEach(longs, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Parameters:
        values - the long array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • forEach

        public static void forEach​(float[] values,
                                   java.util.function.BiConsumer<java.lang.Integer,​java.lang.Float> indexedElementConsumer)
        Iterates over each element of the provided float array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over a primitive float array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         float[] floats = {1.0f, 2.0f, 3.0f};
         ArrayUtils.forEach(floats, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Parameters:
        values - the float array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • forEach

        public static void forEach​(double[] values,
                                   java.util.function.BiConsumer<java.lang.Integer,​java.lang.Double> indexedElementConsumer)
        Iterates over each element of the provided double array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over a primitive double array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         double[] doubles = {1.0, 2.0, 3.0};
         ArrayUtils.forEach(doubles, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Parameters:
        values - the double array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • forEach

        public static <T> void forEach​(T[] values,
                                       java.util.function.BiConsumer<java.lang.Integer,​T> indexedElementConsumer)
        Iterates over each element of the provided array, applying the given BiConsumer to each element with its index.

        This method allows for functional-style iteration over an array, where both the index and the element can be used in the operation. If the array is null or empty, no action is performed.

        Example Usage

        
         String[] strings = {"apple", "banana", "cherry"};
         ArrayUtils.forEach(strings, (index, value) -> System.out.println("Index: " + index + ", Value: " + value));
         
        Type Parameters:
        T - the type of elements in the array
        Parameters:
        values - the array to iterate over
        indexedElementConsumer - the operation to perform on each element, taking the index and the element as arguments
      • contains

        public static boolean contains​(boolean[] values,
                                       boolean value)
        Checks if the specified boolean array contains the given value.

        This method iterates through the array and returns true as soon as it finds an element that matches the specified value according to the equality check for primitive booleans. If no match is found, or if the array is null or empty, it returns false.

        Example Usage

        
         boolean[] array = {true, false, true};
         boolean result1 = ArrayUtils.contains(array, true);  // returns true
         boolean result2 = ArrayUtils.contains(array, false); // returns true
        
         boolean[] emptyArray = {};
         boolean result3 = ArrayUtils.contains(emptyArray, true); // returns false
        
         boolean result4 = ArrayUtils.contains(null, false); // returns false
         
        Parameters:
        values - the boolean array to search within
        value - the value to search for
        Returns:
        true if the array contains the specified value, otherwise false
      • contains

        public static boolean contains​(byte[] values,
                                       byte value)
      • contains

        public static boolean contains​(char[] values,
                                       char value)
        Checks if the specified char array contains the given value using binary search.

        This method assumes that the array is sorted and uses the binary search algorithm to determine whether the array contains the specified value. If the array is not sorted, the result may be incorrect.

        Example Usage

        
         char[] sortedArray = {'a', 'b', 'c', 'd'};
         boolean result1 = ArrayUtils.contains(sortedArray, 'b'); // returns true
         boolean result2 = ArrayUtils.contains(sortedArray, 'e'); // returns false
        
         char[] emptyArray = {};
         boolean result3 = ArrayUtils.contains(emptyArray, 'a'); // returns false
        
         boolean result4 = ArrayUtils.contains(null, 'a'); // returns false
         
        Parameters:
        values - the char array to search within (must be sorted)
        value - the value to search for
        Returns:
        true if the array contains the specified value, otherwise false
      • contains

        public static boolean contains​(short[] values,
                                       short value)
        Checks if the specified short array contains the given value using binary search.

        This method assumes that the array is sorted and uses the binary search algorithm to determine whether the array contains the specified value. If the array is not sorted, the result may be incorrect.

        Example Usage

        
         short[] sortedArray = {1, 2, 3, 4};
         boolean result1 = ArrayUtils.contains(sortedArray, (short) 2); // returns true
         boolean result2 = ArrayUtils.contains(sortedArray, (short) 5); // returns false
        
         short[] emptyArray = {};
         boolean result3 = ArrayUtils.contains(emptyArray, (short) 1); // returns false
        
         boolean result4 = ArrayUtils.contains(null, (short) 1); // returns false
         
        Parameters:
        values - the short array to search within (must be sorted)
        value - the value to search for
        Returns:
        true if the array contains the specified value, otherwise false
      • contains

        public static boolean contains​(int[] values,
                                       int value)
        Checks if the specified int array contains the given value using binary search.

        This method assumes that the array is sorted and uses the binary search algorithm to determine whether the array contains the specified value. If the array is not sorted, the result may be incorrect.

        Example Usage

        
         int[] sortedArray = {1, 2, 3, 4};
         boolean result1 = ArrayUtils.contains(sortedArray, 2); // returns true
         boolean result2 = ArrayUtils.contains(sortedArray, 5); // returns false
        
         int[] emptyArray = {};
         boolean result3 = ArrayUtils.contains(emptyArray, 1); // returns false
        
         boolean result4 = ArrayUtils.contains(null, 1); // returns false
         
        Parameters:
        values - the int array to search within (must be sorted)
        value - the value to search for
        Returns:
        true if the array contains the specified value, otherwise false
      • contains

        public static boolean contains​(long[] values,
                                       long value)
        Checks if the specified long array contains the given value using binary search.

        This method assumes that the array is sorted and uses the binary search algorithm to determine whether the array contains the specified value. If the array is not sorted, the result may be incorrect.

        Example Usage

        
         long[] sortedArray = {1L, 2L, 3L, 4L};
         boolean result1 = ArrayUtils.contains(sortedArray, 2L); // returns true
         boolean result2 = ArrayUtils.contains(sortedArray, 5L); // returns false
        
         long[] emptyArray = {};
         boolean result3 = ArrayUtils.contains(emptyArray, 1L); // returns false
        
         boolean result4 = ArrayUtils.contains(null, 1L); // returns false
         
        Parameters:
        values - the long array to search within (must be sorted)
        value - the value to search for
        Returns:
        true if the array contains the specified value, otherwise false
      • contains

        public static boolean contains​(float[] values,
                                       float value)
        Checks if the specified float array contains the given value using binary search.

        This method assumes that the array is sorted and uses the binary search algorithm to determine whether the array contains the specified value. If the array is not sorted, the result may be incorrect.

        Example Usage

        
         float[] sortedArray = {1.0f, 2.0f, 3.0f, 4.0f};
         boolean result1 = ArrayUtils.contains(sortedArray, 2.0f); // returns true
         boolean result2 = ArrayUtils.contains(sortedArray, 5.0f); // returns false
        
         float[] emptyArray = {};
         boolean result3 = ArrayUtils.contains(emptyArray, 1.0f); // returns false
        
         boolean result4 = ArrayUtils.contains(null, 1.0f); // returns false
         
        Parameters:
        values - the float array to search within (must be sorted)
        value - the value to search for
        Returns:
        true if the array contains the specified value, otherwise false
      • contains

        public static boolean contains​(double[] values,
                                       double value)
        Checks if the specified double array contains the given value using binary search.

        This method assumes that the array is sorted and uses the binary search algorithm to determine whether the array contains the specified value. If the array is not sorted, the result may be incorrect.

        Example Usage

        
         double[] sortedArray = {1.0, 2.0, 3.0, 4.0};
         boolean result1 = ArrayUtils.contains(sortedArray, 2.0); // returns true
         boolean result2 = ArrayUtils.contains(sortedArray, 5.0); // returns false
        
         double[] emptyArray = {};
         boolean result3 = ArrayUtils.contains(emptyArray, 1.0); // returns false
        
         boolean result4 = ArrayUtils.contains(null, 1.0); // returns false
         
        Parameters:
        values - the double array to search within (must be sorted)
        value - the value to search for
        Returns:
        true if the array contains the specified value, otherwise false
      • contains

        public static boolean contains​(java.lang.Object[] values,
                                       java.lang.Object value)
        Checks if the specified object array contains the given value.

        This method iterates through the array and returns true as soon as it finds an element that matches the specified value according to the equality check defined by Object.equals(Object). If no match is found, or if the array is null or empty, it returns false.

        Example Usage

        
         String[] array = {"apple", "banana", "cherry"};
         boolean result1 = ArrayUtils.contains(array, "banana");  // returns true
        
         Integer[] numbers = {1, 2, 3};
         boolean result2 = ArrayUtils.contains(numbers, 2); // returns true
        
         String[] emptyArray = {};
         boolean result3 = ArrayUtils.contains(emptyArray, "apple"); // returns false
        
         boolean result4 = ArrayUtils.contains(null, "apple"); // returns false
         
        Parameters:
        values - the object array to search within
        value - the value to search for
        Returns:
        true if the array contains the specified value, otherwise false
      • arrayToString

        public static <T> java.lang.String arrayToString​(T[] array)
        Converts the specified array to a string representation.

        This method delegates to Arrays.toString(Object[]) to generate a string representation of the provided array. If the array is null, it returns "null".

        Example Usage

        
         String[] strings = {"apple", "banana", "cherry"};
         String result1 = ArrayUtils.arrayToString(strings);
         // result1 contains "[apple, banana, cherry]"
        
         Integer[] numbers = {1, 2, 3};
         String result2 = ArrayUtils.arrayToString(numbers);
         // result2 contains "[1, 2, 3]"
        
         String result3 = ArrayUtils.arrayToString(null);
         // result3 is "null"
         
        Type Parameters:
        T - the type of elements in the array
        Parameters:
        array - the array to convert to a string
        Returns:
        a string representation of the array, or "null" if the array is null
      • reverse

        public static <T> T[] reverse​(T[] a)
        Reverses the elements of the specified array in-place.

        This method reverses the order of elements in the given array. The reversal is done in-place, meaning that no additional memory is used for the operation, and the original array is modified directly.

        Example Usage

        
         String[] strings = {"one", "two", "three"};
         ArrayUtils.reverse(strings);
         // strings now contains ["three", "two", "one"]
        
         Integer[] numbers = {1, 2, 3, 4};
         ArrayUtils.reverse(numbers);
         // numbers now contains [4, 3, 2, 1]
        
         Object[] nullArray = null;
         ArrayUtils.reverse(nullArray); // Throws NullPointerException
         

        (Forks jdk.internal.util.ArraysSupport#reverse(Object[])).

        Type Parameters:
        T - the type of elements in the array
        Parameters:
        a - the array to reverse
        Returns:
        the reversed array (same reference as input)
        Throws:
        java.lang.NullPointerException - if the provided array is null
        See Also:
        jdk.internal.util.ArraysSupport#reverse(Object[])
      • toArrayReversed

        public static <T> T[] toArrayReversed​(java.util.Collection<?> coll,
                                              T[] array)
        Dump the contents of the given collection into the given array, in reverse order. This mirrors the semantics of Collection.toArray(T[]) in regard to reusing the given array, appending null if necessary, or allocating a new array of the same component type.

        A constraint is that this method should issue exactly one method call on the collection to obtain the elements and the size. Having a separate size() call or using an Iterator could result in errors if the collection changes size between calls. This implies that the elements need to be obtained via a single call to one of the toArray() methods. This further implies allocating memory proportional to the number of elements and making an extra copy, but this seems unavoidable.

        An obvious approach would be simply to call coll.toArray(array) and then reverse the order of the elements. This doesn't work, because if given array is sufficiently long, we cannot tell how many elements were copied into it and thus there is no way to reverse the right set of elements while leaving the remaining array elements undisturbed. (Forks jdk.internal.util.ArraysSupport#toArrayReversed(Collection, Object[])).

        Throws:
        java.lang.ArrayStoreException - if coll contains elements that can't be stored in the array
        See Also:
        jdk.internal.util.ArraysSupport#toArrayReversed(Collection, Object[])