public final class ArrayUtil extends Object
Modifier and Type | Method and Description |
---|---|
static int |
computeNewCapacity(int length,
int requiredCapacity)
A convenient method for calling
computeNewCapacity(length, requiredCapacity, 0) . |
static int |
computeNewCapacity(int length,
int requiredCapacity,
int nextCapacityHint)
Computes the size of an array that is required to hold
requiredCapacity number of elements. |
public static int computeNewCapacity(int length, int requiredCapacity)
computeNewCapacity(length, requiredCapacity, 0)
.length
- the current length of the arrayrequiredCapacity
- the immediately required capacityrequiredCapacity
number of elements.computeNewCapacity(int, int, int)
public static int computeNewCapacity(int length, int requiredCapacity, int nextCapacityHint)
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.
length
- the current length of the arrayrequiredCapacity
- the immediately required capacitynextCapacityHint
- a hint for future capacity requirements that may not be required as of nowrequiredCapacity
number of elements.Copyright © 2020. All rights reserved.