public final class GrowingArrayUtils
extends java.lang.Object
A helper class that aims to provide comparable growth performance to ArrayList, but on primitive arrays. Common array operations are implemented for efficient use in dynamic containers.
All methods in this class assume that the length of an array is equivalent to its capacity and NOT the number of elements in the array. The current size of the array is always passed in as a parameter.
| Modifier and Type | Method and Description |
|---|---|
static int[] |
append(int[] array,
int currentSize,
int element)
Appends an element to the end of the array, growing the array if there is no more room.
|
static int |
growSize(int currentSize)
Given the current size of an array, returns an ideal size to which the array should grow.
|
static int[] |
insert(int[] array,
int currentSize,
int index,
int element)
Inserts an element into the array at the specified index, growing the array if there is no
more room.
|
public static int[] append(int[] array,
int currentSize,
int element)
array - The array to which to append the element. This must NOT be null.currentSize - The number of elements in the array. Must be less than or equal to
array.length.element - The element to append.public static int[] insert(int[] array,
int currentSize,
int index,
int element)
array - The array to which to append the element. Must NOT be null.currentSize - The number of elements in the array. Must be less than or equal to
array.length.element - The element to insert.public static int growSize(int currentSize)