Class ArrayUtils


  • public class ArrayUtils
    extends java.lang.Object
    Copied from Apache Commons Lang (including the @since tags.)
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getLength​(java.lang.Object array)
      Returns the length of the specified array.
      static boolean isEmpty​(byte[] array)
      Checks if an array of Objects is empty or null.
      private static java.lang.Object remove​(java.lang.Object array, int index)
      Removes the element at the specified position from the specified array.
      static <T> T[] remove​(T[] array, int index)
      Removes the element at the specified position from the specified array.
      • Methods inherited from class java.lang.Object

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

      • ArrayUtils

        public ArrayUtils()
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(byte[] array)
        Checks if an array of Objects is empty or null.
        Parameters:
        array - the array to test
        Returns:
        true if the array is empty or null
        Since:
        2.1
      • getLength

        public static int getLength​(java.lang.Object array)

        Returns the length of the specified array. This method can deal with Object arrays and with primitive arrays.

        If the input array is null, 0 is returned.

         ArrayUtils.getLength(null)            = 0
         ArrayUtils.getLength([])              = 0
         ArrayUtils.getLength([null])          = 1
         ArrayUtils.getLength([true, false])   = 2
         ArrayUtils.getLength([1, 2, 3])       = 3
         ArrayUtils.getLength(["a", "b", "c"]) = 3
         
        Parameters:
        array - the array to retrieve the length from, may be null
        Returns:
        The length of the array, or 0 if the array is null
        Throws:
        java.lang.IllegalArgumentException - if the object argument is not an array.
        Since:
        2.1
      • remove

        private static java.lang.Object remove​(java.lang.Object array,
                                               int index)

        Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).

        This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.

        If the input array is null, an IndexOutOfBoundsException will be thrown, because in that case no valid index can be specified.

        Parameters:
        array - the array to remove the element from, may not be null
        index - the position of the element to be removed
        Returns:
        A new array containing the existing elements except the element at the specified position.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array.length), or if the array is null.
        Since:
        2.1
      • remove

        public static <T> T[] remove​(T[] array,
                                     int index)

        Removes the element at the specified position from the specified array. All subsequent elements are shifted to the left (subtracts one from their indices).

        This method returns a new array with the same elements of the input array except the element on the specified position. The component type of the returned array is always the same as that of the input array.

        If the input array is null, an IndexOutOfBoundsException will be thrown, because in that case no valid index can be specified.

         ArrayUtils.remove(["a"], 0)           = []
         ArrayUtils.remove(["a", "b"], 0)      = ["b"]
         ArrayUtils.remove(["a", "b"], 1)      = ["a"]
         ArrayUtils.remove(["a", "b", "c"], 1) = ["a", "c"]
         
        Type Parameters:
        T - the component type of the array
        Parameters:
        array - the array to remove the element from, may not be null
        index - the position of the element to be removed
        Returns:
        A new array containing the existing elements except the element at the specified position.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= array.length), or if the array is null.
        Since:
        2.1