Class ArrayUtil


  • public final class ArrayUtil
    extends Object
    Utility methods for arrays.
    • Method Detail

      • computeNewCapacity

        public static int computeNewCapacity​(int length,
                                             int requiredCapacity)
        A convenient method for calling computeNewCapacity(length, requiredCapacity, 0).
        Parameters:
        length - the current length of the array
        requiredCapacity - the immediately required capacity
        Returns:
        the size of an array that is guaranteed to hold requiredCapacity number of elements.
        See Also:
        computeNewCapacity(int, int, int)
      • computeNewCapacity

        public static int computeNewCapacity​(int length,
                                             int requiredCapacity,
                                             int nextCapacityHint)
        Computes the size of an array that is required to hold requiredCapacity number of elements.

        This method first tries to increase the size of the array by a factor of 1.5 to prevent a sequence of successive increases by 1. It then evaluates the nextCapacityHint parameter as well as the requiredCapacity parameter to determine the next size.

        Parameters:
        length - the current length of the array
        requiredCapacity - the immediately required capacity
        nextCapacityHint - a hint for future capacity requirements that may not be required as of now
        Returns:
        the size of an array that is guaranteed to hold requiredCapacity number of elements.